Sleazy Fork is available in English.

Mark Watched Videos for SpankBang

Marks videos that you've previously seen as watched, across the entire site.

Pada tanggal 13 Mei 2021. Lihat %(latest_version_link).

// ==UserScript==
// @namespace   LewdPursuits
// @name        Mark Watched Videos for SpankBang
// @match       *://spankbang.com/*
// @exclude-match     *://spankbang.com/users/history
// @version     0.4.0
// @author      LewdPursuits
// @description Marks videos that you've previously seen as watched, across the entire site.
// @license     GPL-3.0-or-later
// @require     https://cdn.jsdelivr.net/npm/idb-keyval@5/dist/iife/index-min.js
// ==/UserScript==

const historyURL = new URL("https://spankbang.com/users/history");
// This creates the CSS needed to gray out the thumbnail and display the Watched text over it
// The style element is added to the bottom of the body so it's the last style sheet processed
// this ensures these styles take highest priority
const style = document.createElement("style");
style.textContent = `img.watched {
		filter: grayscale(80%);
	}
	div.centered{
		position: absolute;
		color: white;
		height: 100%;
		width: 100%;
		transform: translate(0, -100%);
		z-index: 999;
		text-align: center;
	}
	div.centered p {
		position: relative;
		top: 40%;
		font-size: 1.5rem;
		background: rgba(0,0,0,0.5);
		display: inline;
		padding: 2%;
	}`;
document.body.appendChild(style);
async function getHistoryPage() {
    // This fetch loads the first page of user history
    const response = await fetch(historyURL.href);
    const parser = new DOMParser();
    if (!response.ok) {
        throw new Error(`HTTP error. Status: ${response.status}`);
    }
    // We turn the response into a string representing the page as text
    // We run the text through a DOM parser, which turns it into a useable HTML document
    return parser.parseFromString(await response.text(), "text/html");
}
async function checkStoreLength() {
    const store = await idbKeyval.entries();
    if (store.length === 0) {
        await buildVideoHistory();
    }
    return store;
}
// TODO Add capability to build keyval store from whole history not just first page
async function buildVideoHistory() {
    const doc = await getHistoryPage();
    // This gets the heading that says the number of watched videos, uses regex for 1 or more numbers
    // then gets the matched number as a string and converts it to the number type  
    //const num = Number(doc.querySelector("div.data h2").innerText.match(/\d+/)[0])
    const links = Array.from(doc.querySelectorAll("a.n"));
    const toAdd = links.filter(e => e.href !== undefined)
        .map(e => [e.href, e.innerText]);
    return idbKeyval.setMany(toAdd);
}
async function tagAsWatched() {
    // We check for the existance of any watched videos on the current page
    // If there are any, we move to the thumbnail and add the .watched class
    // This applys the CSS style above, and allows us to easily find the videos again
    const names = Array.from(document.querySelectorAll("a.n"));
    const store = await idbKeyval.keys();
    function tagImg(e) {
        if (store.includes(e.href)) {
            const img = document.querySelector(`#${e.parentElement.id} a picture img`);
            //console.log(`Marking ${e.innerText} as watched`)
            img.classList.add("watched");
            return img;
        }
    }
    return names.filter(e => e.href !== undefined).map(tagImg);
}
function filterWatched() {
    const docQuery = Array.from(document.querySelectorAll("img.watched"));
    function makeDiv(e) {
        let newPara = document.createElement("p");
        newPara.textContent = "Watched";
        let newDiv = document.createElement("div");
        newDiv.classList.add("centered");
        newDiv.appendChild(newPara);
        return e.parentElement.parentElement.appendChild(newDiv);
    }
    return (docQuery.length > 0) ? docQuery.map(makeDiv) : [];
}
async function addPageToStore() {
    const loc = `${window.location}`;
    const query = document.querySelector("div.left h1");
    const title = query ? query.innerText : "";
    const lookup = await idbKeyval.get(loc);
    if (!/spankbang\.com\/\w+\/video\//.test(loc)) {
        return;
    }
    if (lookup !== undefined) {
        return;
    }
    return idbKeyval.set(loc, title);
}
checkStoreLength()
    .then(tagAsWatched)
    .then(filterWatched)
    .then(addPageToStore)
    .catch(e => console.trace(e));