Skip to content

Latest commit

 

History

History
9 lines (8 loc) · 1.41 KB

injectscripttowebsite-js.md

File metadata and controls

9 lines (8 loc) · 1.41 KB
title date categories
InjectScriptToWebsite.Js
2023-11-23
useful-script-en

how to add bookmarklet in chrome
export default { icon: '', name: { en: "Inject script to website", vi: "Embed script on web page", }, description: { en: "", vi: "", }, onClick: function () { / / https://stackoverflow.com/a/26573284 function injectScriptAndUse(src) { var script = document.createElement("script"); script.src = src; script.onload = function() { alert("Inject SUCCESS: " + url); }; script.onerror = function (e) { alert("Inject FAILED. " + e); }; document.querySelector("head")?. appendChild?. (script); } https://stackoverflow.com/a/43467144 function isValidHttpUrl(string) { let url; try { url = new URL(string); } catch (_) { return false; } return url.protocol === "http:" || url.protocol === "https:"; } let url = prompt( "Enter script url / Enter link script: ", "//code.jquery.com/jquery-3.6.1.min.js " ); if (url) { // if (!isValidHttpUrl(url)) alert("URL not valid / Link is invalid"); // else { injectScriptAndUse(url); / / } } }, }; function backup() { // https://stackoverflow.com/a/38840724/11898496 / / Script loader: https://plnkr.co/edit/b9O19f?p=preview&preview }