您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
点击变色并在新窗口打开
当前为
// ==UserScript== // @name 点击变色 // @version 0.36 // @description 点击变色并在新窗口打开 // @match *://*/* // @author 变异小僵尸 // @namespace http://greasyfork.icu/users/85375 // ==/UserScript== (function() { 'use strict'; //变色 var color = "#bbb"; var style = 'a:visited{color:' + color + ' !important}'; addStyle(style); var styles = ''; //获取所有a标签 var a = document.querySelectorAll('a'); for (var i = 0; i < a.length; i++) { a[i].addEventListener('mousedown', function(e) { // e.preventDefault() var that = this; that.addEventListener('click', function(e) { var href = that.getAttribute('href').toLowerCase(); // 判定a标签链接 if (href == "" || href == "#" || href == "javascript:;" || href == "javascript:void(0);" || href == "javascript" || href == "javascript:void(0)") { window.location.href = that.getAttribute('href'); } else { // 阻止默认点击 e.preventDefault(); // 再新窗口打开链接 window.open(that.getAttribute('href')); } }, false); styles = that.getAttribute('style') if (styles !== null) { styles = styles.toLowerCase(); if (styles.indexOf('color:' + color) === -1) { styles += ';color:' + color + ';'; } } else { styles = 'color:' + color + ';'; } //添加 that.setAttribute('style', styles); }, false); } //创建style function addStyle(string) { var style = document.createElement("style"); style.setAttribute("type", "text/css"); if (style.styleSheet) { // IE style.styleSheet.cssText = string; } else { // w3c var cssText = document.createTextNode(string); style.appendChild(cssText); } var heads = document.querySelectorAll("head"); if (heads.length) { heads[0].appendChild(style); } else { document.documentElement.appendChild(style); } } })();