Skip to content

Instantly share code, notes, and snippets.

@hsayed21
Last active October 4, 2022 06:11
Show Gist options
  • Select an option

  • Save hsayed21/a0bae8133deeba509494b72471b6428f to your computer and use it in GitHub Desktop.

Select an option

Save hsayed21/a0bae8133deeba509494b72471b6428f to your computer and use it in GitHub Desktop.

Revisions

  1. hsayed21 revised this gist Oct 4, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pdf-ocr-arabic.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ for (var i = 0; i < elements.length; i++) {
    // scroll to bottom of page
    window.scrollTo(0, document.body.scrollHeight);
    // get downloaded link
    var link = document.querySelector(".dropdown-menu > #download_pdf_searchable");he link
    var link = document.querySelector(".dropdown-menu > #download_pdf_searchable");
    // append the full href to result
    result += link.href + "\n";
    // remove the class "selected" from the current element
  2. hsayed21 created this gist Oct 4, 2022.
    54 changes: 54 additions & 0 deletions pdf-ocr-arabic.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    var result = "";
    // for each on all elements in div with id "grid"
    var elements = document.getElementById("grid").children;
    // get all children divs in div with id "grid"
    for (var i = 0; i < elements.length; i++) {
    // get the current element
    var element = elements[i];
    // add the class "selected" to the current element
    element.classList.add("selected");
    // after that click on ocr button
    document.querySelector(".pdf_ocr").click();
    // wait 2 second
    await new Promise(r => setTimeout(r, 2000));
    // get div with class "modal"
    var modal = document.querySelector("#spin_box");
    // wait until modal class to be "modal" because it will be "modal show" and display: block
    while (modal.classList.contains("show") && modal.style.display == "block") {
    // wait 100ms
    await new Promise(r => setTimeout(r, 1000));
    }
    // scroll to bottom of page
    window.scrollTo(0, document.body.scrollHeight);
    // get downloaded link
    var link = document.querySelector(".dropdown-menu > #download_pdf_searchable");he link
    // append the full href to result
    result += link.href + "\n";
    // remove the class "selected" from the current element
    element.classList.remove("selected");
    // scroll to top of page
    window.scrollTo(0, 0);
    }

    function CopyToClipboard(copyText) {
    navigator.clipboard
    .writeText(copyText)
    .then(() => {
    console.log('copied to clipboard');
    })
    .catch(() => {
    const input = document.createElement('input')
    document.body.appendChild(input)
    input.setAttribute('value', copyText)
    input.select()
    if (document.execCommand('copy')) {
    document.execCommand('copy')
    }
    document.body.removeChild(input)
    console.log('copied to clipboard2');
    })
    }

    console.log(result);
    // copy the result to clipboard
    CopyToClipboard(result);