Greasy Fork

Greasy Fork is available in English.

点击变色

点击变色并在新窗口打开

当前为 2017-02-13 提交的版本,查看 最新版本

// ==UserScript==
// @name         点击变色
// @version      0.11
// @description  点击变色并在新窗口打开
// @connect      *
// @author       变异小僵尸
// @namespace http://greasyfork.icu/users/85375
// ==/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);
        })
    }
})();