666

标题@666

如何插入一段漂亮的代码片

去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

(function () {'use strict';var rules = {black_rule: {name: "black",hook_eventNames: "",unhook_eventNames: ""},default_rule: {name: "default",hook_eventNames: "contextmenu|select|selectstart|copy|cut|dragstart",unhook_eventNames: "mousedown|mouseup|keydown|keyup",dom0: true,hook_addEventListener: true,hook_preventDefault: true,hook_set_returnValue: true,add_css: true}};// 域名列表var lists = {// 黑名单black_list: [/.*\.youtube\.com.*/,/.*\.wikipedia\.org.*/,/mail\.qq\.com.*/,/translate\.google\..*/]};// 要处理的 event 列表var hook_eventNames, unhook_eventNames, eventNames;// 储存名称var storageName = getRandStr('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM', parseInt(Math.random() * 12 + 8));// 储存被 Hook 的函数var EventTarget_addEventListener = EventTarget.prototype.addEventListener;var document_addEventListener = document.addEventListener;var Event_preventDefault = Event.prototype.preventDefault;// Hook addEventListener procfunction addEventListener(type, func, useCapture) {var _addEventListener = this === document ? document_addEventListener : EventTarget_addEventListener;if (hook_eventNames.indexOf(type) >= 0) {_addEventListener.apply(this, [type, returnTrue, useCapture]);} else if (unhook_eventNames.indexOf(type) >= 0) {var funcsName = storageName + type + (useCapture ? 't' : 'f');if (this[funcsName] === undefined) {this[funcsName] = [];_addEventListener.apply(this, [type, useCapture ? unhook_t : unhook_f, useCapture]);}this[funcsName].push(func);} else {_addEventListener.apply(this, arguments);}}// 清理循环function clearLoop() {var elements = getElements();for (var i in elements) {for (var j in eventNames) {var name = 'on' + eventNames[j];if (elements[i][name] !== null && elements[i][name] !== onxxx) {if (unhook_eventNames.indexOf(eventNames[j]) >= 0) {elements[i][storageName + name] = elements[i][name];elements[i][name] = onxxx;} else {elements[i][name] = null;}}}}}// 返回true的函数function returnTrue(e) {return true;}function unhook_t(e) {return unhook(e, this, storageName + e.type + 't');}function unhook_f(e) {return unhook(e, this, storageName + e.type + 'f');}function unhook(e, self, funcsName) {var list = self[funcsName];for (var i in list) {list[i](e);}e.returnValue = true;return true;}function onxxx(e) {var name = storageName + 'on' + e.type;this[name](e);e.returnValue = true;return true;}// 获取随机字符串function getRandStr(chs, len) {var str = '';while (len--) {str += chs[parseInt(Math.random() * chs.length)];}return str;}// 获取所有元素 包括documentfunction getElements() {var elements = Array.prototype.slice.call(document.getElementsByTagName('*'));elements.push(document);return elements;}// 添加cssfunction addStyle(css) {var style = document.createElement('style');style.innerHTML = css;document.head.appendChild(style);}// 获取目标域名应该使用的规则function getRule(url) {function testUrl(list, url) {for (var i in list) {if (list[i].test(url)) {return true;}}return false;}if (testUrl(lists.black_list, url)) {return rules.black_rule;}return rules.default_rule;}// 初始化function init() {// 获取当前域名的规则var url = window.location.host + window.location.pathname;var rule = getRule(url);// 设置 event 列表hook_eventNames = rule.hook_eventNames.split("|");// TODO Allowed to return valueunhook_eventNames = rule.unhook_eventNames.split("|");eventNames = hook_eventNames.concat(unhook_eventNames);// 调用清理 DOM0 event 方法的循环if (rule.dom0) {setInterval(clearLoop, 30 * 1000);setTimeout(clearLoop, 2500);window.addEventListener('load', clearLoop, true);clearLoop();}// hook addEventListenerif (rule.hook_addEventListener) {EventTarget.prototype.addEventListener = addEventListener;document.addEventListener = addEventListener;}// hook preventDefaultif (rule.hook_preventDefault) {Event.prototype.preventDefault = function () {if (eventNames.indexOf(this.type) < 0) {Event_preventDefault.apply(this, arguments);}};}// Hook set returnValueif (rule.hook_set_returnValue) {Event.prototype.__defineSetter__('returnValue', function () {if (this.returnValue !== true && eventNames.indexOf(this.type) >= 0) {this.returnValue = true;}});}console.debug('url: ' + url, 'storageName:' + storageName, 'rule: ' + rule.name);// 添加CSSif (rule.add_css) {addStyle('html, * {-webkit-user-select:text!important; -moz-user-select:text!important;}');}}init();
})();

最新文章

  1. 超过AttGAN,谷歌推出生成文本到图像的新框架 TReCS
  2. 一文详解脑科学研究与产业发展方向
  3. TYVJ1427 小白逛公园
  4. big sur 关闭sip_青岛市第二批拟关闭退出化工生产企业公示
  5. 设计模式工厂方法模式
  6. oracle数据库swap占用率高,物理内存空余很多,swap被持续占用的问题
  7. java乱码base64,解决 JAVA WebSocket 解析 base64 后中文字符串乱码
  8. 【Python CheckiO 题解】Between Markers (simplified)
  9. c++ 麦克风 录音 wav_小米有品上线新品,手机麦克风得到史诗级加强
  10. 使用Filter实现用户自动登录
  11. 其实程序员高工资,好多时候就是加班和自己硬撑出来的
  12. 对于长期需要输出内容的来说,不管公域还是私-域
  13. Chapter 4 Invitations——18
  14. C# decimal保留指定的小数位数,不四舍五入
  15. iOS应用支持IPV6,就那点事儿
  16. 等差、等比数列的求和公式
  17. Raspberry Pi
  18. 浅谈垂心四面体的垂心组
  19. linux ksoftirqd进程,ksoftirqd进程导致cpu消耗殆尽
  20. PythonWeb全栈开发介绍

热门文章

  1. 【软件设计】BDD由内而外采用策略
  2. 关于 pace 有意思的一篇文章
  3. 目标检测-2019年4篇目标检测算法最佳综述
  4. 深入了解电容器,电容器有哪些主要作用?
  5. MATLAB利用最速梯度下降法求解f(x)函数极小点
  6. unity导入Standard Assets出现错误
  7. 什么是收集服务器配置信息,配置rsyslog服务器收集Cisco交换机日志信息操作指引...
  8. tushare 获取复权数据
  9. 湖畔第一大脑蒋烁淼,爱技术也爱创业,送给正在奋斗的你
  10. ES5实现组合继承的原理