Greasy Fork is available in English.

Discussions » Development

Google adds redirect to link

§
Posted: 19-09-2022

I have added a button to the Google Play Store with a hyperlink (IE: example.com), but when I click the button, instead of going to the link, it adds a redirect:
https://www.google.com/url?sa=j&url=example.com&uct=1612440110&usg=3pjOWR1_Mu0aURFTwzxorsd0I1c.

§
Posted: 20-09-2022

Where is your code?

You're probably just not adding https:// before example.com on your html code I guess...

§
Posted: 20-09-2022
Edited: 20-09-2022

I actually use https://

I've used this code many times on different websites with no issues. Seems like the problem is with some code within the website, but I don't know how to bypass it.

I have changed a random link from the page with an URL outside of google play and it does the same thing.

What I noticed, is if I right-click and open in new tab, it works as it should. So I have tried different target/rel tags options with no success.

Here is a stripped down code:

var docEl = document.getElementsByClassName("edaMIf")[0],
    cinkel = document.createElement("div");

cinkel.setAttribute('class','menu-item');
cinkel.innerHTML ='<button style="background-color: #059C72;border: none;color: black;left 10px;text-align: center;font-size: 16px;border-radius: 12px;position: relative;display: inline-block;width: 100%;" class="btn"><a class="href"; href="https://example.com">Example</a></button>';
docEl.after(cinkel);
NotYouMod
§
Posted: 20-09-2022

Just use more JavaScript :)

var docEl = document.getElementsByClassName("edaMIf")[0]
var cinkel = document.createElement("div");

cinkel.setAttribute('class','menu-item');
cinkel.innerHTML = '<button style="background-color: #059C72;border: none;color: black;left 10px;text-align: center;font-size: 16px;border-radius: 12px;position: relative;display: inline-block;width: 100%;" class="btn"><a class="href"; href="https://example.com">Example</a></button>';
cinkel.children[0].innerHTML = '<a class="href" onclick="window.open('https://example.com/someLink')">Example</a>'
docEl.insertAdjacentHTML('afterend', cinkel);

If this doesn't work, you can try this. First connect to your script a library (called Utils), in meta info, like this:

// ==UserScript==
// ...some other info
// @require https://greasyfork.org/scripts/451088/code/utils.js
// ==/UserScript==

Then you can use library functional to do something like that:

var docEl = document.getElementsByClassName("edaMIf")[0]
var cinkel = utils.createElement('div', {
  class: 'menu-item',
});

cinkel.innerHTML = utils.createElement('button', {
  class: 'btn',
  style: 'background-color: #059C72;border: none;color: black;left 10px;text-align: center;font-size: 16px;border-radius: 12px;position: relative;display: inline-block;width: 100%;',
}).outerHTML

cinkel.children[0].innerHTML = utils.createElement('a', {
  class: 'href',
}).outerHTML

cinkel.querySelector('button a').addEventListener('click', function() {
  utils.open('https://example.com/some_example_link')
})
§
Posted: 21-09-2022

Thanks @NotYou, it worked with the javascript

Post reply

Sign in to post a reply.