User:Stumblean/common.js: Difference between revisions

Stumblean (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
Stumblean (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 8: Line 8:
     top: "20px",
     top: "20px",
     right: "20px",
     right: "20px",
     background: "#7889B2", // new background color
     background: "#7889B2",
     color: "#fff",         // white text
     color: "#fff",
     border: "2px solid #666",
     border: "2px solid #666",
     borderRadius: "10px",
     borderRadius: "10px",
Line 34: Line 34:
   title.textContent = "Mahito Menu";
   title.textContent = "Mahito Menu";
   title.style.fontWeight = "bold";
   title.style.fontWeight = "bold";
   title.style.color = "#fff"; // white text
   title.style.color = "#fff";


   const img2 = document.createElement("img");
   const img2 = document.createElement("img");
Line 45: Line 45:
   header.appendChild(img2);
   header.appendChild(img2);


   const btn1 = document.createElement("button");
   function makeButton(text, onclick) {
  btn1.textContent = "Mass undo";
    const btn = document.createElement("button");
   btn1.onclick = function () {
    btn.textContent = text;
    btn.onclick = onclick;
    Object.assign(btn.style, {
      marginBottom: "6px",
      width: "100%",
      cursor: "pointer",
      background: "#45A8C5",
      color: "#fff",
      border: "none",
      padding: "5px 10px",
      borderRadius: "5px",
    });
    return btn;
   }
 
  const btn1 = makeButton("Mass undo", () => {
     prompt("Copy this into your common.js:", "mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/Kill-It-With-Fire.js&action=raw&ctype=text/javascript');");
     prompt("Copy this into your common.js:", "mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/Kill-It-With-Fire.js&action=raw&ctype=text/javascript');");
   };
   });


   const btn2 = document.createElement("button");
   const btn2 = makeButton("Open Explanation", () => {
  btn2.textContent = "Open Explanation";
  btn2.onclick = function () {
     alert("Open Explanation clicked");
     alert("Open Explanation clicked");
  };
  [btn1, btn2].forEach((btn) => {
    btn.style.marginBottom = "6px";
    btn.style.width = "100%";
    btn.style.cursor = "pointer";
    btn.style.background = "#45A8C5"; // new button color
    btn.style.color = "#fff";        // white text
    btn.style.border = "none";
    btn.style.padding = "5px 10px";
    btn.style.borderRadius = "5px";
   });
   });


Line 71: Line 73:
   menu.appendChild(btn1);
   menu.appendChild(btn1);
   menu.appendChild(btn2);
   menu.appendChild(btn2);
  // === IF on common.js ===
  const isCommonJS = location.href.includes("title=") && location.href.match(/common\.js/i);
  if (isCommonJS) {
    const ezBtn = makeButton("EZPASTE", async () => {
      try {
        const clip = await navigator.clipboard.readText();
        await navigator.clipboard.writeText(clip);
        alert("EZPASTE: Clipboard refreshed!");
      } catch (e) {
        alert("Clipboard failed: " + e.message);
      }
    });
    menu.appendChild(ezBtn);
  }
   document.body.appendChild(menu);
   document.body.appendChild(menu);