Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
1,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // @namespace    http://tampermonkey.net/
  2. // @version      0.1
  3. // @description  try to take over the world!
  4. // @author       You
  5. // @include      http*://prnt.sc/*
  6. // @grant        none
  7. // ==/UserScript==
  8.  
  9. (function() {
  10.     const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
  11.     const randomLength = 4;
  12.     const urlBase = 'https://prnt.sc/mp';
  13.  
  14.     function randomPage() {
  15.       let randomPage = [];
  16.       for (let i = 0; i < randomLength; i++) {
  17.         randomPage[i] = chars[Math.floor(Math.random() * chars.length)]
  18.       }
  19.       return urlBase + randomPage.join('');
  20.     }
  21.     function getRandomPage() {
  22.         const r = randomPage();
  23.         this.innerText = r;
  24.         fetch(r).then(res => res.text())
  25.             .then(text => {
  26.                 let src = text.match(/class="no-click screenshot-image" src="(.*?)"/)[1]
  27.                 document.getElementById("screenshot-image").src = src;
  28.                 window.history.pushState({}, "", r);
  29.             })
  30.  
  31.     }
  32.     window.onload = () => {
  33.         const place = document.getElementsByClassName("image-constrain")[0];
  34.         const button = document.createElement("button");
  35.         const block = document.createElement("div");
  36.         block.classList.add("page-constrain");
  37.         button.innerText = "Get Random";
  38.         button.classList.add("image__title");
  39.         button.onclick = getRandomPage;
  40.         block.appendChild(button);
  41.         place.prepend(block);
  42.     }
  43. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement