Monday, October 10, 2016

use Tampermonkey to modify the loaded website the way you like

Tampermonkey is a google chrome extension, it act as the userscript manager, so you can add script to it to change the behaviour of the website the way you like to it behave.

below is the link t o tampermonkey in web store of google chrome

1- the following is the example how to force every link that open in new tab to open in the same tab

2- after install it, the icon of tampermonkey will be seen on the toolbar, so click on it and choose "add a new script"

3- in the script editor paste the following text

// ==UserScript==
// @name         Set all link to open in the same tab
// @namespace
// @version      0.1
// @description  try to take over the world!
// @author       You
// @require
// @match        https://*/*
// @match        http://*/*
// @grant        none
// ==/UserScript==

$(document).ready(function() {
    var alinks = $('a');
    for (i = 0; i < alinks.length; i++) {
        if (alinks[i]['target']  == "_blank"){
            alinks[i].target = '_self';

- on the script above
@match        http://*/*
@match        https://*/*
it means, it apply to every websites. both http and https

4- now every websites you open in chrome, their links will never be open in new tab.

And when you don't want this script to run you can disable the script or disable the tampermonkey.

- snapshot of the script above written in script editor

No comments:

Post a Comment