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

Would it be possible to have selected text as a search query in user defined URL in the Floating WebView?
Like this: https://i.imgur.com/64MAMsM.png

I'm attempting the same thing. Did you manage to figure this out?

@Andreas_Hegenberg if not this, is there a workaround?
This will be sooo handy for quick google searches / dictionary lookups etc :slight_smile:

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

I have had this working for a while now, but is there a way to make it show up the mobile version of the google search page?

This would help because it would fit the window to width and won't require horizontal scrolling to the right and left?

I'm not sure whether google respects the user agent, but youbcan try to set the mobile Safari user agent in thr advanced settings of the web view:

Mozilla/5.0 (iPhone; CPU iPhone OS 16_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Mobile/15E148 Safari/604.1

1 Like

Awesome, yeah I couldn't find the user agent info yesterday online.

That worked perfectly. Thank you :pray: