// ==UserScript== // @name LeetCode_CN/力扣 一键打开英文讨论区 // @namespace Aloxaf_i // @version 0.1.1 // @description 为 LeetCode_CN 添加一键打开英文讨论区的按钮——中文讨论内容太水了 // @author Aloxaf // @match https://leetcode-cn.com/problems/* // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/376339/LeetCode_CN%E5%8A%9B%E6%89%A3%20%E4%B8%80%E9%94%AE%E6%89%93%E5%BC%80%E8%8B%B1%E6%96%87%E8%AE%A8%E8%AE%BA%E5%8C%BA.user.js // @updateURL https://update.greasyfork.icu/scripts/376339/LeetCode_CN%E5%8A%9B%E6%89%A3%20%E4%B8%80%E9%94%AE%E6%89%93%E5%BC%80%E8%8B%B1%E6%96%87%E8%AE%A8%E8%AE%BA%E5%8C%BA.meta.js // ==/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), 500); /* this checks the flag every 100 milliseconds*/ } else { console.log('done'); callback(); } } function add_button() { function htmlToElement(html) { let template = document.createElement('template'); html = html.trim(); // Never return a text node of whitespace as the result template.innerHTML = html; return template.content.firstChild; } const problem_name = location.href.match(/problems\/([^\/]+)/)[1]; const button = ``; document.querySelector('div[class*="-Tools"]').append(htmlToElement(button)); } waitFor(() => { let node = document.querySelector('div[class*="-Tools"]'); return (node && node.childElementCount > 0 ); }, add_button); })();