Advertisement
Guest User

Untitled

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