您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Redirect YouTube to WaniKani if there are reviews available, prompt for API token if not set, recheck every hour, and optionally check for lessons on second visit
当前为
// ==UserScript== // @name Redirect YouTube to WaniKani 18 // @namespace http://tampermonkey.net/ // @version 1 // @description Redirect YouTube to WaniKani if there are reviews available, prompt for API token if not set, recheck every hour, and optionally check for lessons on second visit // @author Your Name // @match https://www.youtube.com/* // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @run-at document-start // @license MIT // ==/UserScript== (function() { 'use strict'; // Function to check WaniKani API function checkWaniKani() { // Get the API token from storage let apiToken = GM_getValue('wanikaniApiToken'); let checkLessons = GM_getValue('checkLessons', null); // Use null to check if it's the first visit // If the API token is not set, prompt the user for it if (!apiToken) { apiToken = prompt('Please enter your WaniKani API token:'); if (apiToken) { GM_setValue('wanikaniApiToken', apiToken); // Force to prompt for lesson checking next time GM_setValue('checkLessons', null); } else { console.error('No API token provided.'); return; } } // If checkLessons preference is not set, ask the user if they want to enable lesson checking if (checkLessons === null) { if (confirm('Would you like to activate lesson checking as well?')) { GM_setValue('checkLessons', true); } else { GM_setValue('checkLessons', false); } // Exit early to avoid making the API call on the first visit return; } // Prepare API URL let apiUrl = 'https://api.wanikani.com/v2/assignments?immediately_available_for_review=true'; if (checkLessons) { apiUrl = 'https://api.wanikani.com/v2/assignments?immediately_available_for_lessons=true'; } console.log('API URL:', apiUrl); // Log the API URL for debugging // Make an API request to WaniKani to check the number of available reviews and lessons GM_xmlhttpRequest({ method: 'GET', url: apiUrl, headers: { 'Authorization': `Bearer ${apiToken}`, 'Wanikani-Revision': '20170710' }, onload: function(response) { try { const data = JSON.parse(response.responseText); const totalCount = data.total_count; console.log('Total Count:', totalCount); // Log the total count for debugging // Check if total count is greater than 0 if (totalCount > 0) { // Redirect to WaniKani window.location.href = 'https://www.wanikani.com'; } } catch (error) { console.error('Error parsing API response:', error); } }, onerror: function(error) { console.error('Error fetching data:', error); } }); } // Run the check initially checkWaniKani(); // Set an interval to check every hour (3,600,000 milliseconds) setInterval(checkWaniKani, 3600000); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址