Skip to content

Commit 67560c0

Browse files
committed
update lc-html
1 parent 07c0d4a commit 67560c0

File tree

2 files changed

+63
-19
lines changed

2 files changed

+63
-19
lines changed

copy-testcase/a.exe

94 KB
Binary file not shown.

lc-to-markdown-txt-html/index.js

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
// ==UserScript==
22
// @name lc-to-markdown-txt-html
33
// @author wuxin0011
4-
// @version 0.0.7
4+
// @version 0.0.8
55
// @namespace https://github.com/wuxin0011/tampermonkey-script/tree/main/lc-to-markdown-txt-html
6-
// @description 力扣题目描述、题解,讨论发布内容复制 复制为 markdown、txt、html 等格式
6+
// @description 力扣题目描述,讨论发布内容复制 复制为 markdown、txt、html 等格式
77
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAABsxJREFUeF7tnVvoZVMcxz9TkkQawoQUEYXECKHcybg+uBUevXibvBC55IXyIG/ePbglwwxyl0suo5FRbjVvNJFMkSTF/tU+Op32Oeu69z5rr+96UWat3/r9vr/P+e21z9n799+ARtUKbKg6egWPAKgcAgEgACpXoPLwVQEEQOUKVB6+KoAAqFyBysNXBRAAlStQefiqAAKgcgUqD18VQABUrkDl4asCCIDKFag8fFUAAVC5ApWHrwogACpXoPLwc1WAQ4GLgc3AccAm0ONmmdn6F9gL7AF2Au8C+1L3SAXgMOAR4E5gv1RntD5IgX+Ap4AHgV+DVs5NTgHgNOAt4IjYzbUuiwI/A5cBu2OsxQJwNvA2cFDMplqTXYE/gEuBz0ItxwBgn/hdwFGhm2l+rwr8CJweejmIAWA7cHWvoch4rALbgBtCFocCcCHwXsgGmju4Ape0dwheG4cCsKO5zmzxsqxJYykQVAVCANgf+B2w/2qsrwJ/AhuBv31cDAHAvuSxLyA01l8BOwx+5eNmCAB28LMDoMb6K3Al8IaPmyEA3Aw862NUc0ZXwHL1vI8XAsBHpfLmCIDycpbVYwGQVc7yjAmA8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HQnK+F+AXhmbFKiAAYpWbyDoBMJFExoYhAGKVm8g6ATCRRMaGIQBilZvIOgEwkUTGhiEAYpWbyDoBMJFExoYhAGKVm8g6ATCRRMaGIQBilZvIOgEwkUTGhiEAYpWbyDoBMJFExobRCwBbgB2xHmndoApYWxvrbeQcrpcm5g1sBnY6LWrCOihwBvCljyMhANgfWfgNsD77GuurgLW12djR2KrT4xAAzMArTRW4Zn1jl2dN+7qX27Z2XmKEAnAdsM3LsiaNpYD9GZ7tvpuHAmDzdzfNok7x3UDzBlVgV0cX05UOhAJgxk5tW5umdLEaVJVKNtvXdhj7PiTeGADM/nltmbHDhsb4Ctjh3G7Trb1d0IgFwDY5GrB+fhcE7ajJuRWwzqLWP/GnGMMpAMz2sxbu1vXa/gCTxnAKfAPcD7yYsmUOAGb7n9+WoePbv8qZ03ZKjFNZa13N9wJ7gFfbFrXJsSlJyRKWbUAAlJ2/ZO8FQLKEZRsQAGXnL9l7AZAsYdkGBEDZ+Uv2XgAkS1i2AQFQdv6SvRcAyRKWbUAAlJ2/ZO8FQLKEZRsQAGXnL9l7AZAsYdkGBEDZ+Uv2XgAkS1i2AQFQdv6SvRcAyRKWbUAAlJ2/ZO8FQLKEZRsQAGXnL9l7AZAsYdkG/gORYKWQd56JTQAAAABJRU5ErkJggg==
88
// @match https://leetcode.cn/circle/discuss/*
99
// @match https://leetcode.cn/discuss/post/*
10-
// @match https://leetcode.com/discuss/post/*
1110
// @match https://leetcode.cn/problems/*
11+
// @match https://leetcode.cn/contest/weekly-contest-*/problems/*
12+
// @match https://leetcode.cn/contest/biweekly-contest-*/problems/*
1213
// @require https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js
1314
// @require https://unpkg.com/[email protected]/dist/turndown.js
1415
// @grant GM_registerMenuCommand
1516
// @grant GM_unregisterMenuCommand
17+
// @grant GM_setClipboard
18+
// @grant GM_addStyle
1619
// @grant GM_setValue
1720
// @grant GM_getValue
18-
// @grant GM_cookie
21+
// @grant GM_getResourceText
22+
// @require https://cdn.jsdelivr.net/npm/[email protected]/lib/noty.min.js
23+
// @resource notycss https://cdn.jsdelivr.net/npm/[email protected]/lib/noty.min.css
24+
// @downloadURL https://update.greasyfork.org/scripts/491969/lc-to-markdown-txt-html.user.js
25+
// @updateURL https://update.greasyfork.org/scripts/491969/lc-to-markdown-txt-html.meta.js
1926
// @license MIT
2027
// ==/UserScript==
2128

2229
(function () {
2330
'use strict';
24-
// 如果需要周赛中启用将下面两个复制到上面
25-
// @match https://leetcode.cn/contest/weekly-contest-*/problems/*
26-
// @match https://leetcode.cn/contest/biweekly-contest-*/problems/*
31+
GM_addStyle(GM_getResourceText('notycss'));
2732
const url = window.location.href
2833
const HTML_CONVERT = '__HTML_CONVERT__'
2934
const TXT_CONVERT = '__TXT_CONVERT__'
@@ -40,7 +45,7 @@
4045
}
4146
console.log('lx-md-html-txt tip:', ...args)
4247
}
43-
const isDiscuss = () => url.indexOf('https://leetcode.cn/circle/discuss') != -1 || url.indexOf('https://leetcode.cn/discuss') != -1
48+
const isDiscuss = () => url.indexOf('https://leetcode.cn/circle/discuss') != -1
4449
const isProblem = () => url.indexOf('https://leetcode.cn/problems') != -1
4550
const isContest = () => url.indexOf('https://leetcode.cn/contest/weekly-contest') != -1 || url.indexOf('https://leetcode.cn/contest/biweekly-contest') != -1
4651

@@ -111,7 +116,7 @@
111116
}
112117

113118

114-
function runQuestionActionsContainer() {
119+
function runQuestionActionsContainer() {
115120
const className = '.break-words';
116121
const questionActionsContainer = document.querySelector('.sticky.bottom-0')
117122
// console.log('questionActionsContainer',questionActionsContainer)
@@ -139,8 +144,6 @@
139144

140145

141146

142-
143-
144147
const toMarkdown = (htmlContent) => {
145148
try {
146149
var turndownService = new TurndownService()
@@ -166,7 +169,7 @@
166169
}
167170

168171
function runProblems() {
169-
// log('~~~ run problem ~~~~', url)
172+
// console.log('~~~ run problem ~~~~', url)
170173
addSolutionButton()
171174
addClickWatch()
172175
let buttonClassName = 'relative inline-flex items-center justify-center text-caption px-2 py-1 gap-1 rounded-full bg-fill-secondary text-difficulty-easy dark:text-difficulty-easy'
@@ -243,6 +246,8 @@
243246

244247
loadSolution(document)
245248
}
249+
250+
// console.log('container',container)
246251
if (!container) {
247252
if (times >= MAX_CNT - 2) {
248253
log('找不到 容器,将手动创建容器!', url)
@@ -252,6 +257,7 @@
252257
if (loadOk) {
253258
return
254259
}
260+
console.log('install contianer ....')
255261
markdownButton.className = buttonClassName
256262
txtButton.className = buttonClassName
257263
htmlButton.className = buttonClassName
@@ -313,6 +319,17 @@
313319
buttonContainer.style.marginTop = '10px'
314320
buttonContainer.style.marginBottom = '10px'
315321
buttonContainer.className = solutionClass
322+
if(solutionContainer.querySelector('span')) {
323+
for(let span of Array.from(solutionContainer.querySelectorAll('span') ?? {length : 0})) {
324+
let cur = span.textContent
325+
cur = cur.toLowerCase()
326+
if(cur.indexOf('create the variable') != -1) {
327+
span.textContent = ''
328+
span.remove()
329+
// console.log('del')
330+
}
331+
}
332+
}
316333
let t = solutionContainer.innerHTML
317334
let buttons = loadButton()
318335
runCopy(buttonContainer, buttons[0], t, SUPPORT_TYPE['md'])
@@ -396,6 +413,12 @@
396413

397414

398415

416+
let CARRAY = ['','','']
417+
418+
419+
420+
421+
399422

400423
function runCopy(container, ele, htmlContent, type = SUPPORT_TYPE['md'], title = '') {
401424

@@ -418,14 +441,17 @@
418441

419442
if (type == SUPPORT_TYPE['md']) {
420443
const markdown = toMarkdown(htmlContent)
444+
CARRAY[1] = markdown
421445
copy(markdown, ele)
422446
} else if (type == SUPPORT_TYPE['txt']) {
423447
const d = document.createElement('div')
424448
d.innerHTML = htmlContent
425449
const txt = handlerText(d.textContent, title)
450+
CARRAY[0] = txt
426451
copy(txt, ele)
427452
} else if (type == SUPPORT_TYPE['html']) {
428453
// html
454+
CARRAY[2] = htmlContent
429455
copy(htmlContent, ele)
430456
} else {
431457
console.warn('no support format ' + type)
@@ -503,6 +529,19 @@
503529

504530

505531

532+
for(let i = 0;i<3;i++) {
533+
let flag = i == 0 ? 'txt' : i == 1 ? 'markdown' : 'html'
534+
GM_registerMenuCommand(`复制为${flag}`, () => {
535+
GM_setClipboard(CARRAY[i])
536+
new Noty({
537+
type: `${CARRAY[i] ? 'success' : 'error'}`,
538+
layout: "topRight",
539+
text: `${flag}复制${CARRAY[i] ? '成功🥰' : '失败😥'}`,
540+
timeout: 2000
541+
}).show();
542+
}, { title: `复制为${flag}`})
543+
}
544+
506545
const html_to_markdown_web = GM_registerMenuCommand('html转换markdown网站', () => {
507546
window.open(markdownURL, '_blank')
508547
}, { title: '如果格式转换有问题,请复制为 html 然后用这个网站转换' })
@@ -522,8 +561,8 @@
522561
}
523562

524563
let times = 0
525-
const MAX_CNT = 15
526-
const TIME_OUT = 1500
564+
const MAX_CNT = 6
565+
const TIME_OUT = 1000
527566
initConmand()
528567

529568

@@ -593,17 +632,22 @@
593632
}
594633

595634

596-
window.onload = () => {
635+
function core() {
597636
times = 0
598-
start()
599637
try {
600-
// loadOK();
638+
start()
601639
} catch (e) {
602-
640+
console.log('start error',e)
641+
}
642+
try {
643+
addClickWatch()
644+
} catch (e) {
645+
console.log('addClickWatch error',e)
603646
}
604-
addClickWatch()
605647
}
606648

649+
core()
650+
607651
// 监听地址改变
608652
// 重新修改描述
609653
let urlChangeLoadOk = false

0 commit comments

Comments
 (0)