12 |
- // @license MIT
- (()=>{const e=Object.freeze({arrowKeySupport:!0,removeUpgradeTab:!0,switchBetweenSites:!0,removeWatermark:!1}),t=!1,n=Object.freeze({name:GM.info.script.name,version:GM.info.script.version,namespace:GM.info.script.namespace});function r(){const t=i();try{"ytm"===t&&(e.arrowKeySupport&&document.addEventListener("keydown",o),e.removeUpgradeTab&&a(),e.removeWatermark||function(){const e=document.createElement("a");e.id="betterytm-watermark",e.className="style-scope ytmusic-nav-bar",e.innerText=n.name,e.title=`${n.name} v${n.version}`,e.href=n.namespace,e.target="_blank",e.rel="noopener noreferrer";const t="\n #betterytm-watermark {\n position: absolute;\n left: 45px;\n top: 43px;\n z-index: 10;\n color: white;\n text-decoration: none;\n cursor: pointer;\n }\n\n #betterytm-watermark:hover {\n text-decoration: underline;\n }\n ",r=document.createElement("style");r.id="betterytm-watermark-style",r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t));document.querySelector("head").appendChild(r);const o=document.querySelector("#left-content");o.parentNode.insertBefore(e,o.nextSibling)}()),e.switchBetweenSites&&function(e){document.addEventListener("keydown",(t=>{"F9"==t.key&&function(e){try{let t;if("ytm"===e?t="music":"yt"===e&&(t="www"),!t)throw new TypeError(`Unrecognized domain '${e}'`);const{pathname:n,search:r,hash:o}=new URL(location.href),c=function(){const e=i();try{if("ytm"===e){return document.querySelector("#progress-bar").value??null}return"yt"===e?0:null}catch(e){return console.error("BetterYTM: Couldn't get video time due to error:",e),null}}()??0,a=`https://${t}.youtube.com${n}${r.includes("?")?`${r}&t=${c}`:`?t=${c}`}${o}`;console.info(`BetterYTM - switching to domain '${e}' at ${a}`),location.href=a}catch(e){console.error("BetterYTM: Error while switching site:",e)}}("yt"===e?"ytm":"yt")}))}(t)}catch(e){console.error("BetterYTM: General error while executing feature:",e)}}function o(e){if(["ArrowLeft","ArrowRight"].includes(e.code)){const n={altKey:!1,bubbles:!0,cancelBubble:!1,cancelable:!0,charCode:0,composed:!0,ctrlKey:!1,currentTarget:null,defaultPrevented:e.defaultPrevented,explicitOriginalTarget:document.body,isTrusted:!0,metaKey:!1,originalTarget:document.body,repeat:!1,shiftKey:!1,srcElement:document.body,target:document.body,type:"keydown",view:window};let r=!1,o={};switch(e.code){case"ArrowLeft":o={code:"KeyH",key:"h",keyCode:72,which:72};break;case"ArrowRight":o={code:"KeyL",key:"l",keyCode:76,which:76};break;default:r=!0}if(r)t;else{const e={...n,...o};document.body.dispatchEvent(new KeyboardEvent("keydown",e))}}}let c=0;function a(){const e=document.querySelector('.ytmusic-nav-bar ytmusic-pivot-bar-item-renderer[tab-id="SPunlimited"]');e?e.remove():c<10&&(setTimeout(a,250),c++)}function i(){const{hostname:e}=new URL(location.href);return e.toLowerCase().includes("music")?"ytm":"yt"}!function(){try{console.log(`${n.name} v${n.version} - ${n.namespace}`),document.addEventListener("DOMContentLoaded",r)}catch(e){console.error("BetterYTM - General Error:",e)}}()})();
|