-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlighter.min.js
1 lines (1 loc) · 2.93 KB
/
highlighter.min.js
1
!function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};const t=(()=>"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==e?e:void 0)();var n=(e=>async(n,o)=>{"string"==typeof n&&(n=(new t.TextEncoder).encode(n)),o={outputFormat:"hex",...o};const i=await t.crypto.subtle.digest(e,n);return"hex"===o.outputFormat?(e=>{const t=new DataView(e);let n="";for(let e=0;e<t.byteLength;e+=4)n+=t.getUint32(e).toString(16).padStart(8,"0");return n})(i):i})("SHA-256");const o="jquery-highlighter-highlighted",i=GM_info.script.name+": clear data",r={enabled:!1},s=function(){return $(this)},a={days:7},c="2/"+GM_info.script.version.split(".")[0],u=(e=>(e.second=e.seconds=1,e.minute=e.minutes=60*e.seconds,e.hour=e.hours=60*e.minutes,e.day=e.days=24*e.hours,e.week=e.weeks=7*e.days,e))({}),l=Symbol();class d{delete(e){const t=this.has(e);return GM_deleteValue(e),t}get(e){const t=GM_getValue(e,l);return t===l?void 0:t}has(e){return GM_getValue(e,l)!==l}keys(){return GM_listValues()}set(e,t){return GM_setValue(e,t),this}}function f(...e){r.enabled&&console.warn(...e)}function g(e,t){for(const n of e.keys()){const o=e.get(n);let i=!0;if(-1===t)f(`purging value (forced): ${n}`);else if("number"!=typeof o.expires||"string"!=typeof o.version)f(`purging invalid value: ${n}:`,o);else if(t>o.expires){f(`purging expired value: ${n} (${new Date(o.expires).toLocaleString()})`)}else o.version!==c?f(`purging obsolete value: ${n} (${o.version})`):i=!1;i&&e.delete(n)}}function p(e,t,n={}){const o=n.context||document,i=typeof t;if("function"===i)return t.apply(o,n.args||[]);if("string"===i)return $(t,o);throw new TypeError(`invalid ${e} selector: expected string or function, got: ${i}`)}jQuery.highlight=(e=>(async function(t){const l=Date.now(),h="cache"in t&&!t.cache?new Map:new d,y="dedup"in t&&!t.dedup,w=function(e){let t=0;for(const n in e)t+=e[n]*(u[n]||0);return 1e3*t}(t.ttl||a),v=t.color||"#FFFD66",m=t.target||s,b=t.id||"id",$=t.item,x=t.onHighlight||function(){};let M;if(r.enabled="debug"in t&&!!t.debug,"function"==typeof b)M=((e,t)=>p("id",b,{context:e,args:t}));else{if("string"!=typeof b)throw new TypeError(`invalid ID selector: expected string or function, got: ${b}`);M=(t=>e(t).attr(b))}if("string"!=typeof $&&"function"!=typeof $)throw new TypeError(`invalid item selector: expected string or function, got: ${$}`);async function G(e){for(const t of e){const e=p("target",m,{context:t}),i=M(t,[e]),r=await n(i),s=h.has(r);if(s&&!y||(e.css("background-color",v),e.addClass(o),x.call(t,e,{id:i,color:v})),!s){const e=l+w,t={expires:e,version:c};f(`caching ${i} (${r}) until ${new Date(e).toLocaleString()}`),h.set(r,t)}}}GM_registerMenuCommand(i,()=>{g(h,-1)}),g(h,l);const _=e(document);if(_.onCreate&&"string"==typeof $)_.onCreate($,G,!0);else{const e=p("item",$);await G(e)}}))(jQuery),jQuery.highlight.className=o,jQuery.highlight.selector="."+o}();