Greasy Fork is available in English.

InjectJS

Inject javascript into almost every website you visit.

Verze ze dne 02. 12. 2022. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name InjectJS
  3. // @namespace http://github.com/YTXaos/InjectJS
  4. // @version 1.17
  5. // @description Inject javascript into almost every website you visit.
  6. // @author YTXaos
  7. // @match *://*/*
  8. // @icon https://raw.githubusercontent.com/YTXaos/InjectJS/main/assets/logo.png
  9. // @grant GM_addElement
  10. // @license MIT
  11. // @require https://code.jquery.com/jquery-3.6.0.min.js
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. "use strict";
  16. const url = location.href,
  17. origin = location.origin,
  18. storage = localStorage,
  19. local_options = ["inject-js:show_alerts", "inject-js:startup_log"];
  20. local_options.forEach(opt => {
  21. let options = JSON.stringify(storage.getItem(opt));
  22. })
  23. function onURL(page, mode) {
  24. switch(mode) {
  25. case "exact":
  26. return url === `${origin}${page}`;
  27. case "relative":
  28. return url.includes(page);
  29. default:
  30. console.error("InjectJS: Specify a matching mode.");
  31. }
  32. }
  33. if(onURL("/inject-js/", "exact")) {
  34. location = "https://github.com/YTXaos/InjectJS";
  35. }
  36. console.info("InjectJS Loaded. Press Ctrl + Q to topen");
  37. const popup = document.createElement("div"),
  38. style = document.createElement("style");
  39. fetch("https://raw.githubusercontent.com/YTXaos/InjectJS/main/assets/main.css").then(get => get.text()).then(set => style.innerHTML = set);
  40. popup.setAttribute("class", "js-injector-popup");
  41. popup.style.display = "none";
  42. popup.innerHTML = `
  43. <label class="js-inject-header">
  44. <div class="js-logo-needle">.....</div>
  45. Inject<span class="js-logo">JS</span></label>
  46. <textarea placeholder="Your code here" class="js-code-inject" spellcheck="off" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false"></textarea>
  47. <button class="execute-code" disabled>Execute</button>`;
  48. document.head.prepend(style);
  49. document.body.prepend(popup);
  50.  
  51. function OptionsPage() {
  52. $("link[rel=stylesheet], style").remove();
  53. document.title = "InjectJS Options";
  54. fetch("https://raw.githubusercontent.com/YTXaos/InjectJS/main/pages/options.html").then(get => get.text()).then(set => document.body.innerHTML = set);
  55. fetch("https://raw.githubusercontent.com/YTXaos/InjectJS/main/options.js").then(get => get.text()).then(set => GM_addElement(document.head, "script", {
  56. textContent: set
  57. }));
  58. }
  59. const code = document.querySelector(".js-code-inject"),
  60. btn = document.querySelector(".execute-code");
  61. code.addEventListener("input", CheckCode);
  62. btn.addEventListener("click", InjectCode);
  63.  
  64. function CheckCode() {
  65. const code = document.querySelector(".js-code-inject");
  66. if(code.value.length < 5) {
  67. btn.setAttribute("disabled", "disabled");
  68. } else {
  69. btn.removeAttribute("disabled");
  70. }
  71. }
  72.  
  73. function InjectCode() {
  74. const code = document.querySelector(".js-code-inject").value;
  75. try {
  76. eval(code);
  77. } catch (e) {
  78. if(options.show_alerts) {
  79. alert(e.message);
  80. } else {
  81. console.error(e.message);
  82. }
  83. }
  84. }
  85.  
  86. function ShowInjector() {
  87. dragElement(document.querySelector(".js-injector-popup"));
  88. function dragElement(elmnt) {
  89. var pos1 = 0,
  90. pos2 = 0,
  91. pos3 = 0,
  92. pos4 = 0;
  93. if(document.querySelector(".js-inject-header")) {
  94. document.querySelector(".js-inject-header").onmousedown = dragMouseDown;
  95. } else {
  96. elmnt.onmousedown = dragMouseDown;
  97. }
  98.  
  99. function dragMouseDown(e) {
  100. e = e || window.event;
  101. e.preventDefault();
  102. pos3 = e.clientX;
  103. pos4 = e.clientY;
  104. document.onmouseup = closeDragElement;
  105. document.onmousemove = elementDrag;
  106. }
  107.  
  108. function elementDrag(e) {
  109. e = e || window.event;
  110. e.preventDefault();
  111. pos1 = pos3 - e.clientX;
  112. pos2 = pos4 - e.clientY;
  113. pos3 = e.clientX;
  114. pos4 = e.clientY;
  115. elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
  116. elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  117. }
  118.  
  119. function closeDragElement() {
  120. document.onmouseup = null;
  121. document.onmousemove = null;
  122. }
  123. }
  124. popup.classList.toggle("show");
  125. }
  126. if(onURL("/inject-js/options", "exact")) {
  127. OptionsPage();
  128. }
  129. document.addEventListener("keyup", function(e) {
  130. e.preventDefault();
  131. if(e.ctrlKey && e.which === 81) {
  132. ShowInjector();
  133. }
  134. });
  135. })();