Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Greasemonkey script

Options
  • 03-10-2016 8:37pm
    #1
    Registered Users Posts: 590 ✭✭✭


    Hello everyone,

    Is it possible to have a script that will change the target URL into a new link?

    source page will create a link similar to this:

    webpage/user1

    i would like to change the link to similar to this

    webpage/user1/webpage

    I have tried several scripts from google and forums but none works

    Thank you for the help


Comments

  • Registered Users Posts: 11,262 ✭✭✭✭jester77


    ldr wrote: »
    Hello everyone,

    Is it possible to have a script that will change the target URL into a new link?

    source page will create a link similar to this:

    webpage/user1

    i would like to change the link to similar to this

    webpage/user1/webpage

    I have tried several scripts from google and forums but none works

    Thank you for the help

    You could do a 301 response


  • Registered Users Posts: 10,493 ✭✭✭✭28064212


    var links = document.getElementsByTagName("a");
    for(var i = 0; i < links.length; i++)
    {
    	if(links[i].href == "webpage/user1")
    		links[i].href = "webpage/user1/webpage";
    }
    

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 590 ✭✭✭ldr


    Thank you for the responses.

    how would i implement the code:

    var links = document.getElementsByTagName("a");
    for(var i = 0; i < links.length; i++)
    {
    if(links.href == "webpage/user1")
    links.href = "webpage/user1/webpage";
    }

    i did install it but i got no results, i did change the webpage/user1 to the meant URL but i got no result.

    i thought i had 3 options to accomplish the end new URL: 1 go to the source page and change the URL of that section, this page retrieves the user name and adds it to the end of the link and opens on new tab. the source page could have dozens of different users.
    the 2nd was to redirect the final URL so when source page create the link and opens a new page then it would be redirected to the desired URL

    the 3rd maybe more easy i think would be every time i reach this page with the user name on the link it would redirect to the new URL containing the user name.

    Unfortunately i cant show you the webpages.

    I have tried examples like this but got no result:
    // ==UserScript==
    // @name whatever
    // @namespace lii
    // @description redirect to anothersite
    // @include http://www.example.net/?image=full&action=view*
    // @version 1
    // @grant none
    // ==/UserScript==

    var links,thisLink;
    links = document.evaluate("//a[@href]&quot;,
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

    for (var i=0;i<links.snapshotLength;i++) {
    var thisLink = links.snapshotItem(i);

    thisLink.href = thisLink.href.replace('http://www.example.net/?image=full&action=view&image',
    'http://www.anothersite.com/download&') + "&thumb=0";

    }


    There is one more possibility from another webpage that contains user name, this information is diplayed in plain text would it be possible to create a hyperlink using the user name?
    example the page displays :
    user: user1

    then the script would create a link like this: http:/blabla.user1.blabla


  • Registered Users Posts: 10,493 ✭✭✭✭28064212


    Use code tags. This should work:
    // ==UserScript==
    // @name        whatever
    // @namespace   lii
    // @description redirect to anothersite
    // @include     http://www.example.net/?image=full&action=view*
    // @version     1
    // @grant       none
    // ==/UserScript==
    
    var links = document.getElementsByTagName("a");
    for(var i = 0; i < links.length; i++)
    {
    	links[i].href = links[i].href.replace('http://www.example.net/?image=full&action=view&image', 'http://www.anothersite.com/download&') + "&thumb=0";
    }
    

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 590 ✭✭✭ldr


    thank you very much for all the help.

    Managed to get it working with my last option:
    There is one more possibility from another webpage that contains user name, this information is diplayed in plain text would it be possible to create a hyperlink using the user name?
    example the page displays :
    user: user1


  • Advertisement
Advertisement