// ==UserScript== // @name LeetCode_CN/力扣 一键打开英文讨论区 // @namespace Aloxaf_i // @version 0.1.0 // @description 为 LeetCode_CN 添加一键打开英文讨论区的按钮——中文讨论内容太水了 // @author Aloxaf // @match https://leetcode-cn.com/problems/* // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js // @grant GM_openInTab // @run-at document-end // @downloadURL none // ==/UserScript== /* jshint esversion: 6 */ (function() { 'use strict'; // https://stackoverflow.com/questions/22125865/wait-until-flag-true function waitFor(condition, callback) { if(!condition()) { console.log('waiting'); window.setTimeout(waitFor.bind(null, condition, callback), 100); /* this checks the flag every 100 milliseconds*/ } else { console.log('done'); callback(); } } function add_button() { const problem_name = location.href.match(/problems\/([^\/]+)/)[1]; const button = ``; $('.tools__wTOC').append($(button)); $('#jump2eng').click(() => GM_openInTab(`https://leetcode.com/problems/${problem_name}/discuss/`)); } waitFor(() => $('.tools__wTOC').length > 0, add_button); })();