Highlight Words Jquery Library

Insructions

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/30368/199089/Highlight%20Words%20Jquery%20Library.js

  1. // ==UserScript==
  2. // @name Highlight Words Jquery Library
  3. // @namespace https://greasyfork.org/en/users/710-tjololo
  4. // @version 0.1
  5. // @description Insructions
  6. // @author Tjololo
  7. // @require http://code.jquery.com/jquery-latest.min.js
  8. // @grant GM_Log
  9. // ==/UserScript==
  10.  
  11. jQuery.fn.highlight=function(c){function e(b,c){var d=0;if(3==b.nodeType){var a=b.data.toUpperCase().indexOf(c),a=a-(b.data.substr(0,a).toUpperCase().length-b.data.substr(0,a).length);if(0<=a){d=document.createElement("span");d.className="highlight";a=b.splitText(a);a.splitText(c.length);var f=a.cloneNode(!0);d.appendChild(f);a.parentNode.replaceChild(d,a);d=1}}else if(1==b.nodeType&&b.childNodes&&!/(script|style)/i.test(b.tagName))for(a=0;a<b.childNodes.length;++a)a+=e(b.childNodes[a],c);return d} return this.length&&c&&c.length?this.each(function(){e(this,c.toUpperCase())}):this};jQuery.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;with(this.parentNode)replaceChild(this.firstChild,this),normalize()}).end()};