Plugin loader UI

Adds an UI to quickly load unsandboxed extensions (plugins).

Fra 22.12.2021. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Plugin loader UI
// @namespace    https://lstv.ml/
// @version      0.1
// @description  Adds an UI to quickly load unsandboxed extensions (plugins).
// @author       LSTV
// @match        https://turbowarp.org/editor*
// @icon         https://www.google.com/s2/favicons?domain=turbowarp.org
// @grant        none
// @license MIT
// ==/UserScript==

/* Preets;
Setup your presets here.
When there is [R] at the begining, the "url" parametter is gonna be treated like url, if there is not, it's gonna be treated like pure code.*/
const presets=[
    {"name":"UtilsV2","url":"[R]https://lstv.ml/cdn/dock/uploads/wQrsblbiSDUtilsV2.js","color":"lime"}
];



/*
You can also load plugins from the console instead of using an UI (For example if you need to load a plugin from url) like this:

window.loadPlugin("[R]https://example.com")

The [R] indicates url. If you don't include it, it will get loaded as the code.
*/

/*code*/
var fetchSucess;
var plbtn=document.createElement('div'), elm=document.createElement('div');plbtn.className="menu-bar_menu-bar-item_oLDa- menu-bar_hoverable_c6WFB";plbtn.onclick="openPlMenu()";plbtn.innerHTML='<div><span>Plugins</span></div>';
window.loadPlugin=function (pl){if(pl.substring(0,10).includes("[R]")){sendRequestTo(pl.substring(3,pl.length), 'load');}else{try{eval(pl);document.querySelector(".plmenu").style.display="none";document.querySelector(".plinput").value="";document.querySelector(".pltextarea").value="";}catch(e){alert("Error loading plugin:\n"+e)}}}
let data;function setData(dt){data=dt;}function sendRequestTo(URLAPI,TAG){fetchSucess=true;fetch(URLAPI).then(response=>response.text()).then( json=>setData(json)).catch(error=>onRequestErrorResponse(error,TAG)).finally(()=>{onRequestResponseRecived(data,TAG);data=null;});}
setTimeout(function (){
document.querySelector("#app > div > div > div > div.gui_menu-bar-position_3U1T0.menu-bar_menu-bar_JcuHF.box_box_2jjDp > div.menu-bar_main-menu_3wjWH > div.menu-bar_file-group_1_CHX").appendChild(plbtn);
plbtn.addEventListener('click', function(e) {document.querySelector(".plmenu").style.display="block";document.querySelector(".plinput").value="";document.querySelector(".pltextarea").value="";window.plRefreshPluginPresets();})
elm.className="plmenu";elm.innerHTML=`
<h1 class="pltitle">Load a custom plugin</h1>
<div class="plmenuix"><br>
<h3>Option 1: Select one of your presets to load:</h3><div class="pl_preset_c"></div><br><br>
<h3>Option 2: Paste the extension code here:</h3><br><textarea class='pltextarea'></textarea><br><button onclick='window.loadPlugin(document.querySelector(".pltextarea").value)' class='plbutton' style="width:90%;">Load</button><br><br>
<h3>Option 3: Or load from an URL</h3><br><br><input type='text' class='plinput' placeholder='Enter an plugin URL'><button onclick='window.loadPlugin("[R]"+document.querySelector(".plinput").value)' class='plbutton'>Load</button><br><br><button onclick='document.querySelector(".plmenu").style.display="none";' class='plbutton' style="color:black;background:white;">Cancel</button></div></div>`;document.body.append(elm);
elm=document.createElement('style');elm.innerHTML=`/* Style */
.pltitle{background:#2d2d2d;position:absolute;top:0px;left:0px;right:0px;height:40px;}
.plmenu{display:none;text-align:center;position:fixed;z-index:99;top:90px;right:380px;left:380px;border-radius:5px;border:5px solid rgba(93, 93, 93,.6);padding:0px;padding-top:40px;min-width:450px;user-select:none;}
.plmenuix{padding:15px;background:#111111;}
.plbutton{background:#fd4c4c;border-radius:5px;padding:10px;border:none;}
.pltextarea{resize:none;height:100px;width:90%;}
.plinput,.pltextarea{color:white;border:1px solid #2d2d2d;border-radius:5px;outline:none;background:#1e1e1e;padding:10px;}
.pl_preset{background:#333333;color:white;padding:10px;border-radius:5px;display:inline-block;cursor:pointer;margin:5px;}
.plcspan{border-radius:300px;padding:0px;width:10px;height:10px;display:inline-block;}
`;document.body.append(elm);}, 800);
function onRequestErrorResponse(error, tag){fetchSucess=false;alert("Failed to load plugin from an url. \nPlease make sure that:\n- You are connected to the internet\n- You load the plugin over https\n- And that the server has setup Access-Control-Allow-Origin header to all or at least turbowarp.org\n\nReturned error message:\n"+error+"\n(Look to the console for details)");}
function onRequestResponseRecived(response, tag){if(fetchSucess){window.loadPlugin(response)}}
window.plRefreshPluginPresets=function(){var container=document.querySelector(".pl_preset_c");container.innerHTML="";for(var i=0;i<presets.length;i++){container.innerHTML=container.innerHTML+`<div class="pl_preset" onclick='window.loadPlugin("`+presets[i].url+`")'><span class="plcspan" style="background:`+presets[i].color+`;"></span> `+presets[i].name+`</div>`;}}