Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Random screenshot button
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @description try to take over the world!
- // @author You
- // @include http*://prnt.sc/*
- // @grant none
- // ==/UserScript==
- (function() {
- const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
- const randomLength = 4;
- const urlBase = 'https://prnt.sc/nr';
- function randomPage() {
- let randomPage = [];
- for (let i = 0; i < randomLength; i++) {
- randomPage[i] = chars[Math.floor(Math.random() * chars.length)]
- }
- return urlBase + randomPage.join('');
- }
- function getRandomPage() {
- const r = randomPage();
- this.innerText = r;
- fetch(r).then(res => res.text())
- .then(text => {
- let src = text.match(/class="no-click screenshot-image" src="(.*?)"/)[1]
- document.getElementById("screenshot-image").src = src;
- window.history.pushState({}, "", r);
- })
- }
- window.onload = () => {
- let place = document.getElementsByClassName("image-constrain")[0];
- if (!place) {
- place = document.getElementsByClassName("page-constrain")[1];
- }
- const button = document.createElement("button");
- const block = document.createElement("div");
- block.classList.add("page-constrain");
- button.innerText = "Get Random";
- button.classList.add("image__title");
- button.onclick = getRandomPage;
- block.appendChild(button);
- place.prepend(block);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement