// ==UserScript== // @name FlashySurf - Flash Cards for Passive learning // @namespace http://tampermonkey.net/ // @version 1.1 // @description A userscript that creates flashcards from your browsing data for passive learning while surfing the web // @author MaxDev // @match *://*/* // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // ==/UserScript== (async function() { 'use strict'; if (window.top !== window.self) { return; } let dataSet = {}; function fetchDataset() { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: "GET", url: "https://raw.githubusercontent.com/MaxDevv/flashysurf/main/questions.json", onload: function(response) { if (response.status === 200) { resolve(JSON.parse(response.responseText)); } else { reject(new Error(`Failed to load dataset: ${response.status}`)); console.error("Failed to load dataset:", response.status); } }, onerror: function(error) { reject(error); console.error("Error loading dataset:", error); } }); }); } dataSet = await fetchDataset(); let questionList = dataSet[(Math.random() > 0.5 ? "math" : "english")]; let flashcard = questionList[Math.floor(Math.random()*questionList.length)]; function createFlashcardWidget(flashcard) { GM_setValue('forceCard', true); let selectedChoice = null; let isCorrect = false; let closeTimer = 20; let forcePause; let intervalId = 0; let btnInterval = 0; if (!forcePause) { forcePause = setInterval(() => { document.querySelectorAll('video').forEach(vid => vid.pause()); }, 100); } // Create container const widgetEl = document.createElement('div'); widgetEl.id = 'flashcard-widget'; // Add styles directly to widget const styles = document.createElement('style'); styles.textContent = ` .background-flashySurfProtectiveStylingClass { position: fixed; top: 0; left: 0; width: 10000vw; height: 100000vh; overflow: hidden; background-color: gray !important; opacity: 70%; z-index: 99999999999999; } .cover-container-flashySurfProtectiveStylingClass { color: black; overflow: hidden; } .widget-flashySurfProtectiveStylingClass { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: max(40vw, 35vh); border-radius: 1.5em; padding: 1.4em; background-color: white !important; border: 0.075em solid black; display: flex; flex-direction: column; font-family: monospace; gap: 1.5em; box-shadow: 0px 0px 60px 3px rgba(0,0,0,0.2); z-index: 999999999999999; color: black !important; } .title-flashySurfProtectiveStylingClass { font-weight: bold; font-size: large; } .limited-flashySurfProtectiveStylingClass { max-height: 10em; overflow-y: scroll; } .choices-flashySurfProtectiveStylingClass { display: flex; flex-direction: column; gap: 0.2em; } .choice-flashySurfProtectiveStylingClass { padding: 2px 4px; border-radius: 6px; text-align: left; background-color: color-mix(in srgb, silver 30%, white 70%); border: none; height: auto !important; color: black !important; cursor: pointer; } .close-button-flashySurfProtectiveStylingClass { padding: 8px 16px; border-radius: 4px; background-color: #007bff; color: white; border: none; cursor: pointer; } .close-button-flashySurfProtectiveStylingClass:disabled { background-color: #ccc; cursor: not-allowed; } `; function getAnswer() { let answer = flashcard.answer; flashcard.choices.forEach((i) => { if (answer[0].toLowerCase() == i[0].toLowerCase()) { answer = i; } }) return answer; } function render() { widgetEl.innerHTML = `