Greasy Fork

4chan sounds

Play that faggy music weeb boi

目前为 2020-05-06 提交的版本。查看 最新版本

// ==UserScript==
// @name         4chan sounds
// @version      0.2.0
// @namespace    rccom
// @description  Play that faggy music weeb boi
// @author       RCC
// @match        *://boards.4chan.org/*
// @match        *://boards.4channel.org/*
// @grant        GM.getValue
// @grant        GM.setValue
// @run-at       document-start
// ==/UserScript==

/**
 * @license
 * Lodash (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE
 * Build: `lodash include="template,get,set" --production`
 */
;(function(){function t(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}function e(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}function r(t){return function(e){return t(e)}}function n(t,r){return e(r,function(e){return t[e]})}function o(t){return"\\"+ft[t]}function u(t,e){return function(r){return t(e(r))}}function c(){}function i(t){var e=-1,r=null==t?0:t.length;
for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function a(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function l(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function f(t,e){var r=Ht(t),n=!r&&Gt(t),o=!r&&!n&&Jt(t),u=!r&&!n&&!o&&Kt(t);if(r=r||n||o||u){for(var n=t.length,c=String,i=-1,a=Array(n);++i<n;)a[i]=c(i);n=a}else n=[];var l,c=n.length;for(l in t)!e&&!St.call(t,l)||r&&("length"==l||o&&("offset"==l||"parent"==l)||u&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||A(l,c))||n.push(l);
return n}function s(t,e,r){var n=t[e];St.call(t,e)&&F(n,r)&&(r!==V||e in t)||_(t,e,r)}function p(t,e){for(var r=t.length;r--;)if(F(t[r][0],e))return r;return-1}function _(t,e,r){"__proto__"==e&&Lt?Lt(t,e,{configurable:true,enumerable:true,value:r,writable:true}):t[e]=r}function h(t){if(null==t)return t===V?"[object Undefined]":"[object Null]";if(Ut&&Ut in Object(t)){var e=St.call(t,Ut),r=t[Ut];try{t[Ut]=V;var n=true}catch(t){}var o=xt.call(t);n&&(e?t[Ut]=r:delete t[Ut]),t=o}else t=xt.call(t);return t}function b(t){
return P(t)&&"[object Arguments]"==h(t)}function y(t){return P(t)&&U(t.length)&&!!at[h(t)]}function g(t,e){return qt(x(t,e,W),t+"")}function j(t){if(typeof t=="string")return t;if(Ht(t))return e(t,j)+"";if(B(t))return Wt?Wt.call(t):"";var r=t+"";return"0"==r&&1/t==-G?"-0":r}function v(t,e){if(Ht(t))return t;var r;return Ht(t)?r=false:(r=typeof t,r=!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!B(t))||(tt.test(t)||!Z.test(t)||null!=e&&t in Object(e))),r?[t]:Vt(C(t))}function d(t,e,r,n){return t===V||F(t,mt[r])&&!St.call(n,r)?e:t;
}function m(t,e){var r=t.__data__,n=typeof e;return("string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==e:null===e)?r[typeof e=="string"?"string":"hash"]:r.map}function O(t,e){var r,n=null==t?V:t[e];return r=!(!L(n)||wt&&wt in n)&&(I(n)?Et:ot).test(E(n)),r?n:V}function A(t,e){var r=typeof t;return e=null==e?9007199254740991:e,!!e&&("number"==r||"symbol"!=r&&ut.test(t))&&-1<t&&0==t%1&&t<e}function S(t,e,r){if(!L(r))return false;var n=typeof e;return!!("number"==n?k(r)&&A(e,r.length):"string"==n&&e in r)&&F(r[e],t);
}function w(t){var e=t&&t.constructor;return t===(typeof e=="function"&&e.prototype||mt)}function x(e,r,n){return r=Bt(r===V?e.length-1:r,0),function(){for(var o=arguments,u=-1,c=Bt(o.length-r,0),i=Array(c);++u<c;)i[u]=o[r+u];for(u=-1,c=Array(r+1);++u<r;)c[u]=o[u];return c[r]=n(i),t(e,this,c)}}function $(t){if(typeof t=="string"||B(t))return t;var e=t+"";return"0"==e&&1/t==-G?"-0":e}function E(t){if(null!=t){try{return At.call(t)}catch(t){}return t+""}return""}function z(t,e){if(typeof t!="function"||null!=e&&typeof e!="function")throw new TypeError("Expected a function");
var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],u=r.cache;return u.has(o)?u.get(o):(n=t.apply(this,n),r.cache=u.set(o,n)||u,n)};return r.cache=new(z.Cache||l),r}function F(t,e){return t===e||t!==t&&e!==e}function k(t){return null!=t&&U(t.length)&&!I(t)}function R(t){if(!P(t))return false;var e=h(t);return"[object Error]"==e||"[object DOMException]"==e||typeof t.message=="string"&&typeof t.name=="string"&&!T(t)}function I(t){return!!L(t)&&(t=h(t),"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t);
}function U(t){return typeof t=="number"&&-1<t&&0==t%1&&9007199254740991>=t}function L(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function P(t){return null!=t&&typeof t=="object"}function T(t){return!(!P(t)||"[object Object]"!=h(t))&&(t=kt(t),null===t||(t=St.call(t,"constructor")&&t.constructor,typeof t=="function"&&t instanceof t&&At.call(t)==$t))}function B(t){return typeof t=="symbol"||P(t)&&"[object Symbol]"==h(t)}function C(t){return null==t?"":j(t)}function M(t){if(k(t))t=f(t);else if(w(t)){
var e,r=[];for(e in Object(t))St.call(t,e)&&"constructor"!=e&&r.push(e);t=r}else t=Tt(t);return t}function D(t){if(k(t))t=f(t,true);else if(L(t)){var e,r=w(t),n=[];for(e in t)("constructor"!=e||!r&&St.call(t,e))&&n.push(e);t=n}else{if(e=[],null!=t)for(r in Object(t))e.push(r);t=e}return t}function N(t){return function(){return t}}function W(t){return t}function q(){return false}var V,G=1/0,H=/\b__p\+='';/g,J=/\b(__p\+=)''\+/g,K=/(__e\(.*?\)|\b__t\))\+'';/g,Q=/[&<>"']/g,X=RegExp(Q.source),Y=/<%=([\s\S]+?)%>/g,Z=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tt=/^\w*$/,et=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,rt=/\\(\\)?/g,nt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ot=/^\[object .+?Constructor\]$/,ut=/^(?:0|[1-9]\d*)$/,ct=/($^)/,it=/['\n\r\u2028\u2029\\]/g,at={};
at["[object Float32Array]"]=at["[object Float64Array]"]=at["[object Int8Array]"]=at["[object Int16Array]"]=at["[object Int32Array]"]=at["[object Uint8Array]"]=at["[object Uint8ClampedArray]"]=at["[object Uint16Array]"]=at["[object Uint32Array]"]=true,at["[object Arguments]"]=at["[object Array]"]=at["[object ArrayBuffer]"]=at["[object Boolean]"]=at["[object DataView]"]=at["[object Date]"]=at["[object Error]"]=at["[object Function]"]=at["[object Map]"]=at["[object Number]"]=at["[object Object]"]=at["[object RegExp]"]=at["[object Set]"]=at["[object String]"]=at["[object WeakMap]"]=false;
var lt,ft={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},st=typeof global=="object"&&global&&global.Object===Object&&global,pt=typeof self=="object"&&self&&self.Object===Object&&self,_t=st||pt||Function("return this")(),ht=typeof exports=="object"&&exports&&!exports.nodeType&&exports,bt=ht&&typeof module=="object"&&module&&!module.nodeType&&module,yt=bt&&bt.exports===ht,gt=yt&&st.process;t:{try{lt=gt&&gt.binding&&gt.binding("util");break t}catch(t){}lt=void 0}var jt=lt&&lt.isTypedArray,vt=function(t){
return function(e){return null==t?V:t[e]}}({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}),dt=Array.prototype,mt=Object.prototype,Ot=_t["__core-js_shared__"],At=Function.prototype.toString,St=mt.hasOwnProperty,wt=function(){var t=/[^.]+$/.exec(Ot&&Ot.keys&&Ot.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),xt=mt.toString,$t=At.call(Object),Et=RegExp("^"+At.call(St).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),zt=yt?_t.Buffer:V,Ft=_t.Symbol,kt=u(Object.getPrototypeOf,Object),Rt=mt.propertyIsEnumerable,It=dt.splice,Ut=Ft?Ft.toStringTag:V,Lt=function(){
try{var t=O(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Pt=zt?zt.isBuffer:V,Tt=u(Object.keys,Object),Bt=Math.max,Ct=Date.now,Mt=O(_t,"Map"),Dt=O(Object,"create"),Nt=Ft?Ft.prototype:V,Wt=Nt?Nt.toString:V;c.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:Y,variable:"",imports:{_:c}},i.prototype.clear=function(){this.__data__=Dt?Dt(null):{},this.size=0},i.prototype.delete=function(t){return t=this.has(t)&&delete this.__data__[t],this.size-=t?1:0,t},
i.prototype.get=function(t){var e=this.__data__;return Dt?(t=e[t],"__lodash_hash_undefined__"===t?V:t):St.call(e,t)?e[t]:V},i.prototype.has=function(t){var e=this.__data__;return Dt?e[t]!==V:St.call(e,t)},i.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Dt&&e===V?"__lodash_hash_undefined__":e,this},a.prototype.clear=function(){this.__data__=[],this.size=0},a.prototype.delete=function(t){var e=this.__data__;return t=p(e,t),!(0>t)&&(t==e.length-1?e.pop():It.call(e,t,1),
--this.size,true)},a.prototype.get=function(t){var e=this.__data__;return t=p(e,t),0>t?V:e[t][1]},a.prototype.has=function(t){return-1<p(this.__data__,t)},a.prototype.set=function(t,e){var r=this.__data__,n=p(r,t);return 0>n?(++this.size,r.push([t,e])):r[n][1]=e,this},l.prototype.clear=function(){this.size=0,this.__data__={hash:new i,map:new(Mt||a),string:new i}},l.prototype.delete=function(t){return t=m(this,t).delete(t),this.size-=t?1:0,t},l.prototype.get=function(t){return m(this,t).get(t)},l.prototype.has=function(t){
return m(this,t).has(t)},l.prototype.set=function(t,e){var r=m(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};var qt=function(t){var e=0,r=0;return function(){var n=Ct(),o=16-(n-r);if(r=n,0<o){if(800<=++e)return arguments[0]}else e=0;return t.apply(V,arguments)}}(Lt?function(t,e){return Lt(t,"toString",{configurable:true,enumerable:false,value:N(e),writable:true})}:W),Vt=function(t){t=z(t,function(t){return 500===e.size&&e.clear(),t});var e=t.cache;return t}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),
t.replace(et,function(t,r,n,o){e.push(n?o.replace(rt,"$1"):r||t)}),e});z.Cache=l;var Gt=b(function(){return arguments}())?b:function(t){return P(t)&&St.call(t,"callee")&&!Rt.call(t,"callee")},Ht=Array.isArray,Jt=Pt||q,Kt=jt?r(jt):y,Qt=function(t){return g(function(e,r){var n=-1,o=r.length,u=1<o?r[o-1]:V,c=2<o?r[2]:V,u=3<t.length&&typeof u=="function"?(o--,u):V;for(c&&S(r[0],r[1],c)&&(u=3>o?V:u,o=1),e=Object(e);++n<o;)(c=r[n])&&t(e,c,n,u);return e})}(function(t,e,r,n){r=D(e);var o=!t;t||(t={});for(var u=-1,c=r.length;++u<c;){
var i=r[u],a=n?n(t[i],e[i],i,t,e):V;a===V&&(a=e[i]),o?_(t,i,a):s(t,i,a)}}),Xt=g(function(e,r){try{return t(e,V,r)}catch(t){return R(t)?t:Error(t)}});c.assignInWith=Qt,c.constant=N,c.keys=M,c.keysIn=D,c.memoize=z,c.set=function(t,e,r){if(null!=t&&L(t)){e=v(e,t);for(var n=-1,o=e.length,u=o-1,c=t;null!=c&&++n<o;){var i=$(e[n]),a=r;if(n!=u){var l=c[i],a=V;a===V&&(a=L(l)?l:A(e[n+1])?[]:{})}s(c,i,a),c=c[i]}}return t},c.extendWith=Qt,c.attempt=Xt,c.eq=F,c.escape=function(t){return(t=C(t))&&X.test(t)?t.replace(Q,vt):t;
},c.get=function(t,e,r){if(null==t)t=V;else{e=v(e,t);for(var n=0,o=e.length;null!=t&&n<o;)t=t[$(e[n++])];t=n&&n==o?t:V}return t===V?r:t},c.identity=W,c.isArguments=Gt,c.isArray=Ht,c.isArrayLike=k,c.isBuffer=Jt,c.isError=R,c.isFunction=I,c.isLength=U,c.isObject=L,c.isObjectLike=P,c.isPlainObject=T,c.isSymbol=B,c.isTypedArray=Kt,c.stubFalse=q,c.template=function(t,e,r){var u=c.templateSettings;r&&S(t,e,r)&&(e=V),t=C(t),e=Qt({},e,u,d),r=Qt({},e.imports,u.imports,d);var i,a,l=M(r),f=n(r,l),s=0;r=e.interpolate||ct;
var p="__p+='",_="sourceURL"in e?"//# sourceURL="+e.sourceURL+"\n":"";if(t.replace(RegExp((e.escape||ct).source+"|"+r.source+"|"+(r===Y?nt:ct).source+"|"+(e.evaluate||ct).source+"|$","g"),function(e,r,n,u,c,l){return n||(n=u),p+=t.slice(s,l).replace(it,o),r&&(i=true,p+="'+__e("+r+")+'"),c&&(a=true,p+="';"+c+";\n__p+='"),n&&(p+="'+((__t=("+n+"))==null?'':__t)+'"),s=l+e.length,e}),p+="';",(e=e.variable)||(p="with(obj){"+p+"}"),p=(a?p.replace(H,""):p).replace(J,"$1").replace(K,"$1;"),p="function("+(e||"obj")+"){"+(e?"":"obj||(obj={});")+"var __t,__p=''"+(i?",__e=_.escape":"")+(a?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+p+"return __p}",
e=Xt(function(){return Function(l,_+"return "+p).apply(V,f)}),e.source=p,R(e))throw e;return e},c.toString=C,c.VERSION="4.17.5",typeof define=="function"&&typeof define.amd=="object"&&define.amd?(_t._=c, define(function(){return c})):bt?((bt.exports=c)._=c,ht._=c):_t._=c}).call(this);
(function(){'use strict';var f=Math.max,g=Math.min,h=Math.floor;async function a(){await n.initialize(),b(document.body);const a=new MutationObserver(function(a){a.forEach(function(a){"childList"===a.type&&a.addedNodes.forEach(function(a){a.nodeType===Node.ELEMENT_NODE&&b(a)})})});a.observe(document.body,{childList:!0,subtree:!0})}function b(a){a.querySelectorAll(".post").forEach(function(a){"qp"===a.parentElement.parentElement.id||a.parentElement.classList.contains("noFile")||a.querySelectorAll(".file").forEach(function(b){c(b,a)})})}function c(a,b){if(!a.classList.contains("file"))return;const c=i?a.querySelector(".fileText .file-info > a"):a.querySelector(".fileText > a");if(!c)return;if(!c.href)return;let d=null;if(i?[a.querySelector(".fileText .file-info .fnfull"),a.querySelector(".fileText .file-info > a")].some(function(a){return a&&(d=a.textContent)}):[a.querySelector(".fileText"),a.querySelector(".fileText > a")].some(function(a){return a&&(d=a.title||"A"===a.tagName&&a.textContent)}),!d)return;d=d.replace(/\-/,"/");const e=d.match(/^(.*)[\[\(\{](?:audio|sound)[ \=\:\|\$](.*?)[\]\)\}]/i);if(!e)return;const f=b.id.slice(1),g=e[1]||f,h=b.querySelector(".fileThumb"),j=h&&h.href,k=h&&h.querySelector("img").src;let l=e[2];if(l.includes("%"))try{l=decodeURIComponent(l)}catch(a){return}null===l.match(/^(https?\:)?\/\//)&&(l=location.protocol+"//"+l);try{l=new URL(l)}catch(a){return}for(let c of n.settings.allow)if(l.hostname.toLowerCase()===c||l.hostname.toLowerCase().endsWith("."+c))return n.add(g,f,l.href,k,j)}function d(){document.body.style.userSelect="none",document.body.style.MozUserSelect="none"}function e(){document.body.style.userSelect=null,document.body.style.MozUserSelect=null}let i;const j=self._,k="fc-sounds",l=[{property:"shuffle",default:!1},{property:"repeat",default:"all"},{property:"playlist",default:!0},{property:"autoshow",default:!0,title:"Autoshow",description:"Automatically show the player when the thread contains sounds.",showInSettings:!0},{property:"pauseOnHide",default:!0,title:"Pause on hide",description:"Pause the player when it's hidden.",showInSettings:!0},{property:"allow",default:["4cdn.org","catbox.moe","dmca.gripe","lewd.se","pomf.cat","zz.ht"],title:"Allow",description:"Which domains sources are allowed to be loaded from.",showInSettings:!0,split:"\n"},{property:"colors.background",default:"#d6daf0",title:"Background Color",showInSettings:!0},{property:"colors.border",default:"#b7c5d9",title:"Border Color",showInSettings:!0},{property:"colors.odd_row",default:"#d6daf0",title:"Odd Row Color",showInSettings:!0},{property:"colors.even_row",default:"#b7c5d9",title:"Even Row Color",showInSettings:!0},{property:"colors.playing",default:"#98bff7",title:"Playing Row Color",showInSettings:!0},{property:"colors.expander",default:"#808bbf",title:"Expander Color",showInSettings:!0},{property:"colors.expander_hover",default:"#9aa6e1",title:"Expander Hover Color",showInSettings:!0}],m={repeat:{all:{title:"Repeat All",text:"[RA]",class:"fa-repeat"},one:{title:"Repeat One",text:"[R1]",class:"fa-repeat fa-repeat-one"},none:{title:"No Repeat",text:"[R0]",class:"fa-repeat disabled"}},shuffle:{true:{title:"Shuffle",text:"[S]",class:"fa-random"},false:{title:"Ordered",text:"[S]",class:"fa-random disabled"}},playlist:{true:{title:"Hide Playlist",text:"[+]",class:"fa-expand"},false:{title:"Show Playlist",text:"[+]",class:"fa-compress"}}},n={ns:k,sounds:[],container:null,ui:{},settings:l.reduce((a,b)=>j.set(a,b.property,b.default),{}),$:(...a)=>n.container.querySelector(...a),templates:{},_templates:{css:"#<%= ns %>-container {\n\tposition: fixed;\n\tbackground: <%= data.colors.background %>;\n\tborder: 1px solid <%= data.colors.border %>;\n\tdisplay: relative;\n\tmin-height: 200px;\n\tmin-width: 100px;\n}\n.<%= ns %>-show-settings .<%= ns %>-player {\n\tdisplay: none;\n}\n.<%= ns %>-setting {\n\tdisplay: none;\n}\n.<%= ns %>-settings {\n\tdisplay: none;\n\tpadding: .25rem;\n}\n.<%= ns %>-show-settings .<%= ns %>-settings {\n\tdisplay: block;\n}\n.<%= ns %>-settings .<%= ns %>-setting-header {\n\tfont-weight: 600;\n\tmargin-top: 0.25rem;\n}\n.<%= ns %>-settings textarea {\n\tborder: solid 1px <%= data.colors.border %>;\n\tmin-width: 100%;\n\tmin-height: 4rem;\n\tbox-sizing: border-box;\n}\n.<%= ns %>-title {\n\tcursor: grab;\n\ttext-align: center;\n\tborder-bottom: solid 1px <%= data.colors.border %>;\n\tpadding: .25rem 0;\n}\nhtml.fourchan-x .<%= ns %>-title a {\n\tfont-size: 0;\n\tvisibility: hidden;\n\tmargin: 0 0.15rem;\n}\nhtml.fourchan-x  .<%= ns %>-title .fa-repeat.fa-repeat-one::after {\n\tcontent: '1';\n\tfont-size: .5rem;\n\tvisibility: visible;\n\tmargin-left: -1px;\n}\n.<%= ns %>-image-link {\n\ttext-align: center;\n\tdisplay: flex;\n\tjustify-items: center;\n\tjustify-content: center;\n\tborder-bottom: solid 1px <%= data.colors.border %>;\n}\n.<%= ns %>-playlist-view .<%= ns %>-image-link {\n\theight: 125px !important;\n}\n.<%= ns %>-expanded-view .<%= ns %>-image-link {\n\theight: auto ;\n\tmin-height: 125px;\n}\n.<%= ns %>-image-link .<%= ns %>-video {\n\tdisplay: none;\n}\n.<%= ns %>-image-link.<%= ns %>-show-video .<%= ns %>-video {\n\tdisplay: block;\n}\n.<%= ns %>-image-link.<%= ns %>-show-video .<%= ns %>-image {\n\tdisplay: none;\n}\n.<%= ns %>-image, .<%= ns %>-video {\n\theight: 100%;\n\twidth: 100%;\n\tobject-fit: contain;\n}\n.<%= ns %>-audio {\n\twidth: 100%;\n}\n.<%= ns %>-list-container {\n\toverflow: auto;\n}\n.<%= ns %>-expanded-view .<%= ns %>-list-container {\n\tdisplay: none;\n}\n.<%= ns %>-list {\n\tdisplay: grid;\n\tlist-style-type: none;\n\tpadding: 0;\n\tmargin: 0;\n}\n.<%= ns %>-list-item {\n\tlist-style-type: none;\n\tpadding: 0.15rem 0.25rem;\n\twhite-space: nowrap;\n\tcursor: pointer;\n}\n.<%= ns %>-list-item.playing {\n\tbackground: <%= data.colors.playing %> !important;\n}\n.<%= ns %>-list-item:nth-child(n) {\n\tbackground: <%= data.colors.odd_row %>;\n}\n.<%= ns %>-list-item:nth-child(2n) {\n\tbackground: <%= data.colors.even_row %>;\n}\n.<%= ns %>-footer {\n\tpadding: .15rem .25rem;\n\tborder-top: solid 1px <%= data.colors.border %>;\n}\n.<%= ns %>-expander {\n\tposition: absolute;\n\tbottom: 0px;\n\tright: 0px;\n\theight: .75rem;\n\twidth: .75rem;\n\tcursor: se-resize;\n\tbackground: linear-gradient(to bottom right, rgba(0,0,0,0), rgba(0,0,0,0) 50%, <%= data.colors.expander %> 55%, <%= data.colors.expander %> 100%)\n}\n.<%= ns %>-expander:hover {\n\tbackground: linear-gradient(to bottom right, rgba(0,0,0,0), rgba(0,0,0,0) 50%, <%= data.colors.expander_hover %> 55%, <%= data.colors.expander_hover %> 100%)\n}",body:"<div id=\"<%= ns %>-container\" class=\"<%= ns %>-<%= data.playlist ? 'playlist' : 'extended' %>-view\" style=\"top: 100px; left: 100px; width: 350px; display: none;\">\n\t<div class=\"<%= ns %>-title\" style=\"display: flex; flex-wrap: wrap; justify-content: between;\">\n\t\t<%= Player.templates.header({ data }) %>\n\t</div>\n\t<div class=\"<%= ns %>-player\">\n\t\t<a class=\"<%= ns %>-image-link\" style=\"height: 128px\" target=\"_blank\">\n\t\t\t<img class=\"<%= ns %>-image\"></img>\n\t\t\t<video class=\"<%= ns %>-video\"></video>\n\t\t</a>\n\t\t<div class=\"<%= ns %>-controls\">\n\t\t\t<div class=\"<%= ns %>-play-pause\"></div>\n\t\t\t<div class=\"<%= ns %>-play-pause\"></div>\n\t\t</div>\n\t\t<audio class=\"<%= ns %>-audio\" controls=\"true\"></audio>\n\t\t<div class=\"<%= ns %>-list-container\" style=\"height: 100px\">\n\t\t\t<ul class=\"<%= ns %>-list\">\n\t\t\t\t<%= Player.templates.list({ data }) %>\n\t\t\t</ul>\n\t\t</div>\n\t\t<div class=\"<%= ns %>-footer\">\n\t\t\t<span class=\"<%= ns %>-count\">0</span> sounds\n\t\t\t<div class=\"<%= ns %>-expander\"></div>\n\t\t</div>\n\t</div>\n\t<div class=\"<%= ns %>-settings\">\n\t\t<%= Player.templates.settings({ data }) %>\n\t</div>\n</div>",header:"<div style=\"flex: 0 0 auto; width: auto; max-width: 100%; margin-left: 0.25rem;\">\n\t<% Object.keys(headerOptions).forEach(key => { %>\n\t\t<% let option = headerOptions[key][data[key]] || headerOptions[key][0]; %>\n\t\t<a class=\"<%= ns %>-<%= key %>-button fa <%= option.class %>\" title=\"<%= option.title %>\" href=\"javascript;\">\n\t\t\t<%= option.text %>\n\t\t</a>\n\t<% }) %>\n</div><div style=\"flex-basis: 0; flex-grow: 1; max-width: 100%; width: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;\">\n\t<%= Player.playing ? Player.playing.title : '4chan Sounds' %>\n</div>\n<div style=\"flex: 0 0 auto; width: auto; max-width: 100%; margin-right: 0.25rem;\">\n\t<a class=\"<%= ns %>-config-button fa fa-wrench\" title=\"Settings\" href=\"javascript;\">Settings</a>\n\t<a class=\"<%= ns %>-close-button fa fa-times\" href=\"javascript;\">X</a>\n</div>",list:"<% Player.sounds.forEach(sound => { %>\n\t<li class=\"<%= ns %>-list-item <%= sound.playing ? 'playing' : '' %>\" data-id=\"<%= sound.id %>\">\n\t\t<%= sound.title %>\n\t</li>\n<% }) %>",settings:"<% settingsConfig.forEach(setting => { %>\n\t<% if (setting.showInSettings) { %>\n\t\t<div class=\"<%= ns %>-setting-header\" <%= setting.title ? `title=\"${setting.desc}\"` : '' %>><%= setting.title %></div>\n\t\t<% if (typeof setting.default === 'boolean') { %>\n\t\t\t<input type=\"checkbox\" data-property=\"<%= setting.property %>\" <%= _.get(data, setting.property, false) ? 'checked' : '' %>></input>\n\t\t<% } else if (Array.isArray(setting.default)) { %>\n\t\t\t<textarea data-property=\"<%= setting.property %>\"><%= _.get(data, setting.property, '').join(setting.split) %></textarea>\n\t\t<% } else { %>\n\t\t\t<input type=\"text\" data-property=\"<%= setting.property %>\" value=\"<%= _.get(data, setting.property, '') %>\"></input>\n\t\t<% } %>\n\t<% } %>\n<% }); %>"},events:{click:{[`.${k}-close-button`]:"hide",[`.${k}-config-button`]:"toggleSettings",[`.${k}-shuffle-button`]:"toggleShuffle",[`.${k}-repeat-button`]:"toggleRepeat",[`.${k}-playlist-button`]:"togglePlaylist",[`.${k}-list`]:function(a){const b=a.target.getAttribute("data-id"),c=b&&n.sounds.find(function(a){return a.id===""+b});c&&n.play(c)}},mousedown:{[`.${k}-title`]:"initMove",[`.${k}-expander`]:"initResize"},focusout:{[`.${k}-settings input, .${k}-settings textarea`]:"handleSettingChange"},change:{[`.${k}-settings input[type=checkbox]`]:"handleSettingChange"}},initialize:async function(){for(let a in await n.loadSettings(),n.sounds=[],n.playOrder=[],n._templates)n.templates[a]=j.template(n._templates[a]);if(i){const a=document.getElementById("shortcuts"),b=document.createElement("span");a.insertBefore(b,document.getElementById("shortcut-settings"));const c={id:"shortcut-sounds",class:"shortcut brackets-wrap","data-index":0};for(let a in c)b.setAttribute(a,c[a]);b.innerHTML="<a href=\"javascript:;\" title=\"Sounds\" class=\"fa fa-play-circle\">Sounds</a>",b.querySelector("a").addEventListener("click",n.toggleDisplay)}else document.querySelectorAll("#settingsWindowLink, #settingsWindowLinkBot").forEach(function(a){const b=document.createTextNode("] ["),c=document.createElement("a");c.innerHTML="Sounds",c.href="javascript;",a.parentNode.insertBefore(c,a),a.parentNode.insertBefore(b,a),c.addEventListener("click",n.toggleDisplay)});n.render()},saveSettings:function(){return GM.setValue(k+".settings",JSON.stringify(n.settings))},loadSettings:async function(){function a(b,c){for(let d in c)c[d]&&"object"==typeof c[d]&&!Array.isArray(c[d])?(b[d]||(b[d]={}),a(b[d],c[d])):b[d]=c[d]}let b=await GM.getValue(k+".settings");if(b){try{b=JSON.parse(b)}catch(a){return}a(n.settings,b)}},_tplOptions:function(){return{data:n.settings}},render:async function(){n.container&&(document.body.removeChild(n.container),document.head.removeChild(n.stylesheet)),n.stylesheet=document.createElement("style"),n.stylesheet.innerHTML=n.templates.css(n._tplOptions()),document.head.appendChild(n.stylesheet);const a=document.createElement("div");for(let b in a.innerHTML=n.templates.body(n._tplOptions()),n.container=a.querySelector(`#${k}-container`),document.body.appendChild(n.container),n.audio=n.$(`.${k}-audio`),n.events)n.container.addEventListener(b,function(a){for(let c in n.events[b]){let d=n.events[b][c];"string"==typeof d&&(d=n[d]);const e=a.target.closest(c);if(e)return a.eventTarget=e,d(a)}});n.audio.addEventListener("ended",n.next),n.audio.addEventListener("pause",()=>n.$(`.${k}-video`).pause()),n.audio.addEventListener("play",()=>{n.$(`.${k}-video`).currentTime=n.audio.currentTime,n.$(`.${k}-video`).play()}),n.audio.addEventListener("seeked",()=>n.$(`.${k}-video`).currentTime=n.audio.currentTime)},renderHeader:function(){n.$(`.${k}-title`).innerHTML=n.templates.header(n._tplOptions())},renderList:function(){n.$(`.${k}-list`)&&(n.$(`.${k}-list`).innerHTML=n.templates.list(n._tplOptions()))},renderSettings:function(){if(n.$(`.${k}-settings`)){return void(n.$(`.${k}-settings`).innerHTML=n.templates.settings(n._tplOptions()))}},toggleDisplay:function(a){a&&a.preventDefault(),"none"===n.container.style.display?n.show():n.hide()},hide:function(a){a&&a.preventDefault(),n.container.style.display="none"},show:async function(a){if(a&&a.preventDefault(),!n.container.style.display)return;n.container.style.display=null;const[b,c]=((await GM.getValue(k+".position"))||"").split(":"),[d,e]=((await GM.getValue(k+".size"))||"").split(":");+d&&+e&&n.resizeTo(d,e),+b&&+c&&n.moveTo(b,c)},toggleRepeat:function(a){a.preventDefault();const b=Object.keys(m.repeat),c=b.indexOf(n.settings.repeat);n.settings.repeat=b[(c+4)%3],n.renderHeader(),n.saveSettings()},toggleShuffle:function(a){if(a.preventDefault(),n.settings.shuffle=!n.settings.shuffle,n.renderHeader(),!n.settings.shuffle)n.playOrder=[...n.sounds];else{const a=n.playOrder;for(let b=a.length-1;0<b;b--){const c=h(Math.random()*(b+1));[a[b],a[c]]=[a[c],a[b]]}}n.saveSettings()},toggleSettings:function(a){a.preventDefault(),n.container.classList.contains(k+"-show-settings")?n.container.classList.remove(k+"-show-settings"):n.container.classList.add(k+"-show-settings")},handleSettingChange:function(a){const b=a.eventTarget,c=b.getAttribute("data-property"),d=l.find(a=>a.property===c),e=j.get(n.settings,c);let f=b["checkbox"===b.getAttribute("type")?"checked":"value"];d&&d.split&&(f=f.split(decodeURIComponent(d.split))),e!==f&&(j.set(n.settings,c,f),n.stylesheet.innerHTML=n.templates.css(n._tplOptions()),n.saveSettings())},initResize:function(a){d(),n._startX=a.clientX,n._startY=a.clientY,n._startWidth=parseInt(document.defaultView.getComputedStyle(n.container).width,10),n._startHeight=parseInt(document.defaultView.getComputedStyle(n.container).height,10),document.documentElement.addEventListener("mousemove",n.doResize,!1),document.documentElement.addEventListener("mouseup",n.stopResize,!1)},doResize:function(a){n.resizeTo(n._startWidth+a.clientX-n._startX,n._startHeight+a.clientY-n._startY)},resizeTo:function(a,b){b=g(b,document.documentElement.clientHeight-40),n.container.style.width=a+"px";const c=n.settings.playlist?n.$(`.${k}-list-container`):n.$(`.${k}-image-link`),d=parseInt(document.defaultView.getComputedStyle(n.container).height,10),e=d-parseInt(c.style.height,10);c.style.height=f(10,b-e)+"px"},stopResize:function(){const a=document.defaultView.getComputedStyle(n.container);document.documentElement.removeEventListener("mousemove",n.doResize,!1),document.documentElement.removeEventListener("mouseup",n.stopResize,!1),e(),GM.setValue(k+".size",parseInt(a.width,10)+":"+parseInt(a.height,10))},initMove:function(a){d(),n.$(`.${k}-title`).style.cursor="grabbing";const b=document.defaultView.getComputedStyle(n.container);n.resizeTo(parseInt(b.width,10),parseInt(b.height,10)),n._offsetX=a.clientX-n.container.offsetLeft,n._offsetY=a.clientY-n.container.offsetTop,document.documentElement.addEventListener("mousemove",n.doMove,!1),document.documentElement.addEventListener("mouseup",n.stopMove,!1)},doMove:function(a){n.moveTo(a.clientX-n._offsetX,a.clientY-n._offsetY)},moveTo:function(a,b){const c=document.defaultView.getComputedStyle(n.container),d=document.documentElement.clientWidth-parseInt(c.width,10),e=document.documentElement.clientHeight-parseInt(c.height,10);n.container.style.left=f(0,g(a,d))+"px",n.container.style.top=f(0,g(b,e))+"px"},stopMove:function(){document.documentElement.removeEventListener("mousemove",n.doMove,!1),document.documentElement.removeEventListener("mouseup",n.stopMove,!1),n.$(`.${k}-title`).style.cursor=null,e(),GM.setValue(k+".position",parseInt(n.container.style.left,10)+":"+parseInt(n.container.style.top,10))},showThumb:function(a){n.$(`.${k}-image-link`).classList.remove(k+"-show-video"),n.$(`.${k}-image`).src=a.thumb,n.$(`.${k}-image-link`).href=a.image},showImage:function(a){n.$(`.${k}-image-link`).classList.remove(k+"-show-video"),n.$(`.${k}-image`).src=a.image,n.$(`.${k}-image-link`).href=a.image},playVideo:function(a){n.$(`.${k}-image-link`).classList.add(k+"-show-video"),n.$(`.${k}-video`).src=a.image,n.$(`.${k}-video`).play()},hidePlaylist:function(){n.settings.playlist=!1,n.container.classList.add(`${k}-expanded-view`),n.container.classList.remove(`${k}-playlist-view`),n.saveSettings()},showPlaylist:function(){n.settings.playlist=!0,n.container.classList.remove(`${k}-expanded-view`),n.container.classList.add(`${k}-playlist-view`),n.saveSettings()},togglePlaylist:function(a){a&&a.preventDefault(),n.settings.playlist?n.hidePlaylist():n.showPlaylist()},add:function(a,b,c,d,e){if(!n.sounds.find(a=>a.id===b)){const f={title:a,src:c,id:b,thumb:d,image:e};n.sounds.push(f);const g=n.settings.shuffle?h(Math.random()*n.sounds.length-1):n.sounds.length;n.playOrder.splice(g,0,f),n.renderList(),n.$(`.${k}-count`).innerHTML=n.sounds.length,1===n.playOrder.length&&(/\/thread\//.test(location.href)&&n.settings.autoshow&&n.show(),n.showThumb(f))}},play:function(a){a&&(n.playing&&(n.playing.playing=!1),a.playing=!0,n.playing=a,n.renderHeader(),n.audio.src=a.src,a.image.endsWith(".webm")?n.playVideo(a):n.showImage(a),n.renderList()),n.audio.play()},pause:function(){n.audio.pause()},next:function(){n._movePlaying(1)},previous:function(){n._movePlaying(-1)},_movePlaying:function(a){if(!n.playOrder.length)return;const b=n.playOrder.indexOf(n.playing);if(-1===b)return n.playSound(n.playOrder[0]);const c="one"===n.settings.repeat?b:"all"===n.settings.repeat?(b+a+n.playOrder.length)%n.playOrder.length:b+a,d=n.playOrder[c];d&&n.play(d)}};j.templateSettings.imports.ns=k,j.templateSettings.imports.Player=n,j.templateSettings.imports.settingsConfig=l,j.templateSettings.imports.headerOptions=m;document.addEventListener("DOMContentLoaded",function(){setTimeout(function(){(document.body.classList.contains("ws")||document.body.classList.contains("nws"))&&a()},1)}),document.addEventListener("4chanXInitFinished",function(){document.documentElement.classList.contains("fourchan-x")&&document.documentElement.classList.contains("sw-yotsuba")&&(i=!0,a())})})();