// ==UserScript== // @name 点击变色 // @version 0.11 // @description 点击变色并在新窗口打开 // @connect * // @author 变异小僵尸 // @namespace https://greasyfork.org/users/85375 // @downloadURL none // ==/UserScript== (function() { 'use strict'; //变色 var color = "red"; var targets = ''; var target = '_blank'; var styles = ''; //获取所有a标签 var a = document.querySelectorAll('a'); for (var i = 0; i < a.length; i++) { targets = a[i].getAttribute('target'); if (targets != target) { a[i].setAttribute('target', target); } a[i].addEventListener('mousedown', function(e) { var that = this; styles = that.getAttribute('style'); if (styles != null) { var t = styles.substring(styles.length - 1, styles.length) if (t == ';') { styles += 'color:' + color + ';'; } else { styles += ';color:' + color + ';'; } } else { styles = 'color:' + color + ';'; } //添加 that.setAttribute('style', styles); }) } })();