MCPcopy
hub / github.com/QasimWani/LeetHub / parseQuestion

Function parseQuestion

scripts/leetcode.js:440–497  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

438
439/* Parser function for the question and tags */
440function parseQuestion() {
441 var questionUrl = window.location.href;
442 if (questionUrl.endsWith('/submissions/')) {
443 questionUrl = questionUrl.substring(
444 0,
445 questionUrl.lastIndexOf('/submissions/') + 1,
446 );
447 }
448 const questionElem = document.getElementsByClassName(
449 'content__u3I1 question-content__JfgR',
450 );
451 const questionDescriptionElem = document.getElementsByClassName(
452 'question-description__3U1T',
453 );
454 if (checkElem(questionElem)) {
455 const qbody = questionElem[0].innerHTML;
456
457 // Problem title.
458 let qtitle = document.getElementsByClassName('css-v3d350');
459 if (checkElem(qtitle)) {
460 qtitle = qtitle[0].innerHTML;
461 } else {
462 qtitle = 'unknown-problem';
463 }
464
465 // Problem difficulty, each problem difficulty has its own class.
466 const isHard = document.getElementsByClassName('css-t42afm');
467 const isMedium = document.getElementsByClassName('css-dcmtd5');
468 const isEasy = document.getElementsByClassName('css-14oi08n');
469
470 if (checkElem(isEasy)) {
471 difficulty = 'Easy';
472 } else if (checkElem(isMedium)) {
473 difficulty = 'Medium';
474 } else if (checkElem(isHard)) {
475 difficulty = 'Hard';
476 }
477 // Final formatting of the contents of the README for each problem
478 const markdown = `<h2><a href="${questionUrl}">${qtitle}</a></h2><h3>${difficulty}</h3><hr>${qbody}`;
479 return markdown;
480 } else if (checkElem(questionDescriptionElem)) {
481 let questionTitle = document.getElementsByClassName(
482 'question-title',
483 );
484 if (checkElem(questionTitle)) {
485 questionTitle = questionTitle[0].innerText;
486 } else {
487 questionTitle = 'unknown-problem';
488 }
489
490 const questionBody = questionDescriptionElem[0].innerHTML;
491 const markdown = `<h2>${questionTitle}</h2><hr>${questionBody}`;
492
493 return markdown;
494 }
495
496 return null;
497}

Callers 1

leetcode.jsFile · 0.85

Calls 1

checkElemFunction · 0.85

Tested by

no test coverage detected