XenoMorph616

skip-ms-learn-modules

Jun 2nd, 2023 (edited)
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:
  2. /* =============== Copy/paste all of this code as the content of a bookmark in your browser =============== */
  3. (function skipMSLearnModules(
  4.   documentUrl = window.location.href.split("?")[0],
  5.   innerDocument = document
  6. ) {
  7.   /* Discard query string from URL as it was interfering with regex matching */
  8.   const urlRegex =
  9.     /https?:\/\/([^/]+)\/([^/]+\/)?(learn|training)\/(\w+)\/([\w-]+)\/([^/]*)/g;
  10.   const allMatches = [...documentUrl.matchAll(urlRegex)];
  11.   const [url, domain, locale, area, pathOrModule, module, unit] = [
  12.     ...allMatches[0],
  13.   ];
  14.  
  15.   if (pathOrModule == "paths") {
  16.     const moduleLinks = innerDocument.querySelectorAll(
  17.       'a[data-linktype="relative-path"][class~="text-decoration-none"]'
  18.     );
  19.     moduleLinks.forEach((module) => window.open(module.href, "_blank"));
  20.   } else if (pathOrModule == "modules") {
  21.     if (!unit) {
  22.       const iframeContainer = innerDocument.createElement("div");
  23.       iframeContainer.style = `
  24.         padding-top: 80vh;
  25.         position: absolute;
  26.         inset: 0;
  27.         z-index: 1000;`;
  28.  
  29.       innerDocument.body.insertAdjacentElement("afterbegin", iframeContainer);
  30.       const unitLinks = innerDocument.querySelectorAll(
  31.         'a[class~="unit-title"]'
  32.       );
  33.  
  34.       unitLinks.forEach((unit) => {
  35.         const iframe = innerDocument.createElement("iframe");
  36.         iframe.src = unit.href;
  37.         iframe.style = `
  38.             outline: 2px dashed orangered;
  39.             width: 90vw;
  40.             height: 50vh;`;
  41.  
  42.         iframe.addEventListener("load", () => {
  43.           setTimeout(() => {
  44.             skipMSLearnModules(iframe.src, iframe.contentDocument);
  45.           }, 500);
  46.         });
  47.         iframeContainer.insertAdjacentElement("beforeend", iframe);
  48.       });
  49.     } else {
  50.       const radioButtons = innerDocument.querySelectorAll(
  51.         'input[type=radio][id*="quiz-choice-"][id$="-0"]'
  52.       );
  53.  
  54.       radioButtons.forEach((radio) => {
  55.         radio.checked = true;
  56.         innerDocument
  57.           .querySelector('button[data-bi-name="check-answers"]')
  58.           .click();
  59.       });
  60.     }
  61.   }
  62. })();
  63.  
Advertisement
Add Comment
Please, Sign In to add comment