Search code examples
javascriptwebtampermonkey

Maintain active links with Tampermonkey designMode on?


I created a script at Tampermonkey, where I can change any website.

This is my script:

    // ==UserScript==
// @name         Edit any Website
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match      *://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    // javascript:document.body.contentEditable = 'true' ;
    document.designMode='on' ;
    void 0
})();

But my problem is, when I click on hyperlinks/links, nothing happens, but the input field appears (which is actually the point of this script), but I want the input field to appear only when I don’t click on links (so it should be normal to open the links I click on). Is that possible and can someone help me how to adjust it?


Solution

  • U already tried something like this?

        // ==UserScript==
    // @name         Edit any Website
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  try to take over the world!
    // @author       You
    // @match      *://*/*
    // @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
    // @grant        none
    // ==/UserScript==
    (function () {
        'use strict';
        // javascript:document.body.contentEditable = 'true' ;
        document.designMode = 'on';
    
        document.querySelectorAll('a').forEach((a) => {
            a.addEventListener('click', (e) => {
                location = e.currentTarget.href;
            })
        })
    })();