scripts/leetcode.js
/* - Also call the callback if available when upload is success */
Also call the callback if available when upload is success
Also call the callback if available when upload is success
function findCode(uploadGit, problemName, fileName, msg, action, cb=undefined) {
  var submissionURL;
  const e = document.getElementsByClassName('status-column__3SUg');
  if (checkElem(e)) {
    const submissionRef = e[1].innerHTML.split(' ')[1];
    submissionURL = "https://leetcode.com" + submissionRef.split('=')[1].slice(1, -1);
  } else{
    const submissionRef = document.getElementById('result-state');
    submissionURL = submissionRef.href;
  }
  if (submissionURL != undefined) {
    const xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
      if (this.readyState == 4 && this.status == 200) {
        var doc = new DOMParser().parseFromString(
          this.responseText,
          'text/html',
        );
        var scripts = doc.getElementsByTagName('script');
        for (var i = 0; i < scripts.length; i++) {
          var text = scripts[i].innerText;
          if (text.includes('pageData')) {
            var firstIndex = text.indexOf('submissionCode');
            var lastIndex = text.indexOf('editCodeUrl');
            var slicedText = text.slice(firstIndex, lastIndex);
            var firstInverted = slicedText.indexOf("'");
            var lastInverted = slicedText.lastIndexOf("'");
            var codeUnicoded = slicedText.slice(
              firstInverted + 1,
              lastInverted,
            );
            var code = codeUnicoded.replace(
              /\\u[\dA-F]{4}/gi,
              function (match) {
                return String.fromCharCode(
                  parseInt(match.replace(/\\u/g, ''), 16),
                );
              },
            );
            if(!msg){
              slicedText = text.slice(text.indexOf("runtime"),text.indexOf("memory"));
              const resultRuntime = slicedText.slice(slicedText.indexOf("'")+1,slicedText.lastIndexOf("'"));
              slicedText = text.slice(text.indexOf("memory"),text.indexOf("total_correct"));
              const resultMemory = slicedText.slice(slicedText.indexOf("'")+1,slicedText.lastIndexOf("'"));
              msg = `Time: ${resultRuntime}, Memory: ${resultMemory} -LeetHub`; 
            }
            if (code != null) {
              setTimeout(function () {
                uploadGit(
                  btoa(unescape(encodeURIComponent(code))),
                  problemName,
                  fileName,
                  msg,
                  action,
                  true,
                  cb
                );
              }, 2000);
            }
          }
        }
      }
    };
    xhttp.open('GET', submissionURL, true);
    xhttp.send();
  }
}
function findCode ( uploadGit , problemName , fileName , msg , action , cb = undefined ) { var submissionURL ; const e = document . getElementsByClassName ( 'status-column__3SUg' ) ; if ( checkElem ( e ) ) { const submissionRef = e [ 1 ] . innerHTML . split ( ' ' ) [ 1 ] ; submissionURL = "https://leetcode.com" + submissionRef . split ( '=' ) [ 1 ] . slice ( 1 , - 1 ) ; } else { const submissionRef = document . getElementById ( 'result-state' ) ; submissionURL = submissionRef . href ; } if ( submissionURL != undefined ) { const xhttp = new XMLHttpRequest ( ) ; xhttp . onreadystatechange = function ( ) { if ( this . readyState == 4 && this . status == 200 ) { var doc = new DOMParser ( ) . parseFromString ( this . responseText , 'text/html' , ) ; var scripts = doc . getElementsByTagName ( 'script' ) ; for ( var i = 0 ; i < scripts . length ; i ++ ) { var text = scripts [ i ] . innerText ; if ( text . includes ( 'pageData' ) ) { var firstIndex = text . indexOf ( 'submissionCode' ) ; var lastIndex = text . indexOf ( 'editCodeUrl' ) ; var slicedText = text . slice ( firstIndex , lastIndex ) ; var firstInverted = slicedText . indexOf ( "'" ) ; var lastInverted = slicedText . lastIndexOf ( "'" ) ; var codeUnicoded = slicedText . slice ( firstInverted + 1 , lastInverted , ) ; var code = codeUnicoded . replace ( / \\u[\dA-F]{4} / gi , function ( match ) { return String . fromCharCode ( parseInt ( match . replace ( / \\u / g , '' ) , 16 ) , ) ; } , ) ; if ( ! msg ) { slicedText = text . slice ( text . indexOf ( "runtime" ) , text . indexOf ( "memory" ) ) ; const resultRuntime = slicedText . slice ( slicedText . indexOf ( "'" ) + 1 , slicedText . lastIndexOf ( "'" ) ) ; slicedText = text . slice ( text . indexOf ( "memory" ) , text . indexOf ( "total_correct" ) ) ; const resultMemory = slicedText . slice ( slicedText . indexOf ( "'" ) + 1 , slicedText . lastIndexOf ( "'" ) ) ; msg = ` ${ resultRuntime } ${ resultMemory } ` ; } if ( code != null ) { setTimeout ( function ( ) { uploadGit ( btoa ( unescape ( encodeURIComponent ( code ) ) ) , problemName , fileName , msg , action , true , cb ) ; } , 2000 ) ; } } } } } ; xhttp . open ( 'GET' , submissionURL , true ) ; xhttp . send ( ) ; } }
Also call the callback if available when upload is success
Also call the callback if available when upload is success
/* Get the submission details url from the submission page. */ // for normal problem submisson // for a submission in explore section /* Request for the submission details page */ /* received submission details as html reponse. */ /* the response has a js object called pageData. */ /* Pagedata has the details data with code about that submission */ /* Considering the pageData as text and extract the substring
            which has the full code */ /* slicedText has code as like as. (submissionCode: 'Details code'). */ /* So finding the index of first and last single inverted coma. */ /* Extract only the code */ /* The code has some unicode. Replacing all unicode with actual characters */ /*
            for a submisssion in explore section we do not get probStat beforehand
            so, parse statistics from submisson page
            */