Add Waifus to LMS

Adds waifus from Danbooru to Learning Management Systems. Works by default on Tec de Monterrey Links and Google Classroom's, but can be easily tweaked to allow for other websites! Images have permanence. Click an image to delete it and reload to get a new one.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Add Waifus to LMS
// @namespace   Violentmonkey Scripts
// @match       https://experiencia21.tec.mx/courses/*/modules
// @match       https://experiencia21.tec.mx/courses/*/assignments
// @match       https://experiencia21.tec.mx/courses/*/assignments/*
// @match       https://classroom.google.com/u/*
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_deleteValue
// @require     https://code.jquery.com/jquery-3.6.0.min.js
// @grant       none
// @version     1.0
// @author      Mauville @ Github
// @description Adds waifus from Danbooru to Learning Management Systems. Works by default on Tec de Monterrey Links and Google Classroom's, but can be easily tweaked to allow for other websites! Images have permanence. Click an image to delete it and reload to get a new one.
// ==/UserScript==

// Purges image from DB. Hides it
let purgeImg = () => {
    GM_deleteValue(hashCode(document.URL))
    $("#waifu").hide()

}
// Injects image into DOM. Gives it listener
let injectImg = (htmlimg) => {
    // Finds application element. Change this to reflect other
    $("body").append(htmlimg)
    $("#waifu").css({
        'z-index': '9999',
        'position': 'fixed',
        'right': '9em',
        'bottom': '0',
        'max-height': '40%'
    });
    $("#waifu").on("click", purgeImg)
}

// Common hashCode function to convert URL into serial
function hashCode(source) {
    let hash = 0;
    if (source.length == 0) {
        return hash;
    }
    for (var i = 0; i < source.length; i++) {
        var char = source.charCodeAt(i);
        hash = ((hash << 5) - hash) + char;
        hash = hash & hash; // Convert to 32bit integer 
    }
    return hash;
}

let img = "NULL IMAGE"
let page = Math.floor(Math.random() * 850)
let memoised = GM_getValue(hashCode(document.URL), false)

if (false == memoised) {
    // get images from danbooru. Tags are HD, transparent and SFW
    $.getJSON("https://danbooru.donmai.us/posts.json?tags=transparent_background+highres+rating:s&page=" + page, function(data) {
        //sort images by filesize and choose random from bottom 3
        data.sort((a, b) => parseFloat(a.file_size) - parseFloat(b.file_size));
        let newurl = data[Math.floor(Math.random() * 3)].file_url;
        img = '<img id=waifu src="' + newurl + '">'
        //memoise for next time
        GM_setValue(hashCode(document.URL), newurl)
        injectImg(img)

    });
} else {
    img = '<img id=waifu src="' + memoised + '">'
    injectImg(img)
}