Selected text as search query (%@) in Floating WebView

I just tried and with current BTT versions it works like this:


So first add an action with the predefined action "Save selected text to variable selected text"

Then in the webview use code like this to retrieve the variable:

<html>
<style>
// spinner from https://loading.io/css/
.lds-dual-ring {
  display: inline-block;
  width: 80px;
  height: 80px;
}
.lds-dual-ring:after {
  content: " ";
  display: block;
  width: 64px;
  height: 64px;
  margin: 8px;
  border-radius: 50%;
  border: 6px solid #fff;
  border-color: #fff transparent #fff transparent;
  animation: lds-dual-ring 1.2s linear infinite;
}
@keyframes lds-dual-ring {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>
<script>

async function BTTInitialize() {


let selectedText = await callBTT("get_string_variable", {variableName:"selected_text"})

window.location.href="https://www.google.com/search?q=" + encodeURIComponent(selectedText);


}

</script>
<body>
<div  style="with:100%; height:100%; display:flex; align-items:center;align-content:center; justify-content:center">
<div class="lds-dual-ring"></div>
</div>
</body>
</html>

Make sure to also check this option:

1 Like