// ==UserScript== // @name 阿里云掌控版 // @namespace http://tampermonkey.net/ // @version 1.0.1 // @description try to take over the world! // @author wd // @match https://*.aliyun.com/* // @match https://www.tapd.cn/* // @icon https://www.google.com/s2/favicons?domain=aliyun.com // @grant none // @run-at document-start // ==/UserScript== const SELF = '_self'; const BLANK = '_blank'; (function() { 'use strict'; let isPressed = false; const makeKeyListener = (state) => { return e => { if (['Meta', 'Control'].includes(e.key)) { isPressed = state // console.log(state, e, isPressed); } }; } window.addEventListener('keydown', makeKeyListener(true)); window.addEventListener('keyup', makeKeyListener(false)); // window.open const navigate = (href) => Object.assign(document.createElement("a"), { href, target: isPressed ? BLANK : SELF }).click(); window.open = (url) => navigate(url); // anchor setInterval(() => { document.querySelectorAll("a").forEach(e => { e.target = SELF }); }); const observer = new MutationObserver(mutationList => { mutationList.forEach(mutation => { // console.log(mutation.addedNodes); if (mutation.addedNodes.length) { mutation.addedNodes.forEach(node => { if (node instanceof HTMLAnchorElement) node.target = SELF; }) } }) }); const checkReady = () => { const body = document.getElementsByTagName("body")[0]; if (!body) return setTimeout(checkReady, 1000); observer.observe(body, { childList: true }); } checkReady(); })();