Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name zasrywacz 2.0
- // @match https://karachan.org/*
- // @grant GM_xmlhttpRequest
- // @connect www.hovno.sk
- // @run-at document-end
- // ==/UserScript==
- function getRandomPictureUrl() {
- const page = Math.floor(Math.random() * 920) + 1;
- return new Promise(resolve => {
- GM_xmlhttpRequest({
- method: 'GET',
- url: `https://www.hovno.sk/galeria?strana=${page}`,
- onload: function (response) {
- const doc = new DOMParser().parseFromString(
- response.responseText,
- 'text/html'
- );
- const images = doc.querySelectorAll('a.list-group-item.shit img');
- const randomImage =
- images[Math.floor(Math.random() * images.length)];
- const picture = randomImage.closest('a.list-group-item.shit');
- const title = picture.querySelector('span:not(.badge)').textContent.trim();
- console.log(title);
- const fullUrl = randomImage.src.replace(
- '/img/thumb/',
- '/img/full/'
- );
- resolve({
- url: fullUrl,
- title: title
- });
- }
- });
- });
- }
- function downloadAndSetFile(url, title) {
- GM_xmlhttpRequest({
- method: 'GET',
- url: url,
- responseType: 'blob',
- onload: function (response) {
- const file = new File(
- [response.response],
- title + '.jpg',
- { type: response.response.type }
- );
- const input = document.querySelector(
- 'input.upload[name="upfile"]'
- );
- const dataTransfer = new DataTransfer();
- dataTransfer.items.add(file);
- input.files = dataTransfer.files;
- input.dispatchEvent(
- new Event('change', { bubbles: true })
- );
- }
- });
- }
- function createButton() {
- const replyCell = document.querySelector('td.ladda-td');
- if (!replyCell) return;
- const button = document.createElement('button');
- button.textContent = 'zapostuj gówno';
- button.type = 'button';
- button.classList.add('ladda-button');
- button.dataset.style = 'expand-right';
- button.dataset.size = 'xs';
- button.dataset.color = 'mint';
- button.style.marginLeft = '6px';
- button.style.verticalAlign = 'top';
- button.addEventListener('click', async function () {
- const picture = await getRandomPictureUrl();
- downloadAndSetFile(picture.url, picture.title);
- document.querySelector('input.board-input[name="email"]').value = 'sage';
- document.querySelector('button.ladda-button .ladda-label').closest('button').click();
- });
- replyCell.appendChild(button);
- }
- createButton();
Advertisement
Add Comment
Please, Sign In to add comment