นี่คือ UserScript อื่นซึ่ง wraps องค์ประกอบใด ๆ กับonclick="document.location='some_url'"แอตทริบิวต์ในองค์ประกอบและลบ<a href=some_url>onclick
ฉันเขียนลงในเว็บไซต์เฉพาะ แต่เป็นเรื่องทั่วไปพอที่จะเป็นประโยชน์กับผู้อื่น อย่าลืมเปลี่ยน@match URL ด้านล่าง
สิ่งนี้จะทำงานเมื่อลิงก์ถูกโหลดโดยการเรียก AJAX ดังนั้น MutationObserver
// ==UserScript==
// @name         JavaScript link fixer
// @version      0.1
// @description  Change JavaScript links to open in new tab/window
// @author       EM0
// @match        http://WHATEVER-WEBSITE-YOU-WANT/*
// @grant        none
// ==/UserScript==
var modifyLink = function(linkNode) {
    // Re-create the regex every time, otherwise its lastIndex needs to be reset
    var linkRegex = /document\.location\s*=\s*\'([^']+)\'/g;
    var onclickText = linkNode.getAttribute('onclick');
    if (!onclickText)
        return;
    var match = linkRegex.exec(onclickText);
    if (!match) {
        console.log('Failed to find URL in onclick text ' + onclickText);
        return;
    }
    var targetUrl = match[1];
    console.log('Modifying link with target URL ' + targetUrl);
    // Clear onclick, so it doesn't match the selector, before modifying the DOM
    linkNode.removeAttribute('onclick');
    // Wrap the original element in a new <a href='target_url' /> element
    var newLink = document.createElement('a');
    newLink.href = targetUrl;
    var parent = linkNode.parentNode;
    newLink.appendChild(linkNode);
    parent.appendChild(newLink);
};
var modifyLinks = function() {
    var onclickNodes = document.querySelectorAll('*[onclick]');
    [].forEach.call(onclickNodes, modifyLink);
};
var observeDOM = (function(){
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    return function(obj, callback) {
        if (MutationObserver) {
            var obs = new MutationObserver(function(mutations, observer) {
                if (mutations[0].addedNodes.length || mutations[0].removedNodes.length)
                    callback();
            });
            obs.observe(obj, { childList:true, subtree:true });
        }
    };
})();
(function() {
    'use strict';
    observeDOM(document.body, modifyLinks);
})();