Naurok Bypass v2: Extras

Companion userscript for naurok bypass; Contains unstable and unfinished features and enhancements for the Testing pages.

目前為 2023-12-15 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Naurok Bypass v2: Extras
// @description Companion userscript for naurok bypass; Contains unstable and unfinished features and enhancements for the Testing pages.
// @author      griffi-gh
// @namespace   griffi-gh
// @match       https://naurok.com.ua/test/testing/*
// @grant       none
// @grant       GM_addStyle
// @version     0.3
// @run-at      document-idle
// @inject-into page
// @sandbox     DOM
// @connect     naurok.com.ua
// @icon        https://play-lh.googleusercontent.com/scIkpmsUJTfDbV39X0rb-AvxbgxOrpa9zIGJQqDHP1VbuBTmortXomSSWVZnpErwyA=w480-h960
// ==/UserScript==

"use strict";

let session_info;

async function loadSessionInfo() {
  //Get session ID
  const session_id = document.querySelector(`[ng-app="testik"]`).getAttribute("ng-init").match(/[0-9]+/g)[1];
  console.log("Session id: ", session_id);

  //Get session info from API
  session_info = await fetch(`https://naurok.com.ua/api2/test/sessions/${session_id}`, {
    credentials: "include",
    headers: {
      'Accept': 'application/json, text/plain, */*',
      'Content-Type': 'application/json'
    },
    redirect: 'follow',
  }).then(x => x.json());
  console.log("Session info: ", session_info);
}

function displayUi() {
  //Add test name to the page
  const testContainer = document.querySelector('.test-container')

  const infoNode = document.createElement("div");
  infoNode.classList.add("x-test-info");
  testContainer.insertBefore(infoNode, testContainer.firstChild);

  const nameNode = document.createElement("div");
  nameNode.classList.add("x-test-name");
  infoNode.append(nameNode);
  nameNode.textContent = `${session_info.settings.name}`;

  const buttonsNode = document.createElement("div");
  buttonsNode.classList.add("x-button-container");
  infoNode.append(buttonsNode);

  let xButton

  xButton = document.createElement("a");
  buttonsNode.append(xButton);
  xButton.classList.add("x-button");
  xButton.textContent = "Результати інших учнів";
  xButton.href = `https://naurok.com.ua/test/homework/${session_info.settings.id}/detailed-export/score`;

  xButton = document.createElement("a");
  buttonsNode.append(xButton);
  xButton.classList.add("x-button");
  xButton.textContent = "Наступні питання";
  xButton.href = `javascript:alert("TODO")`;

}

function applyStyles() {
  let styleCss = `
    /* allow selection */
    * {
      -webkit-user-select: unset !important;
      -webkit-touch-callout: unset !important;
      -moz-user-select: unset !important;
      -ms-user-select: unset !important;
      user-select: unset !important;
    }

    /* style our own ui */
    .test-container {
      display: flex !important;
      flex-direction: row !important;
    }
    .test-container > :last-child {
      flex-grow: 1 !important;
    }

    .x-test-info {
      background: white;
      border-radius: 1rem;
      max-width: 20vw;
      min-width: 200px;
      margin: 1rem;
      padding: 1rem;
      box-shadow: 0 0 .5rem rgba(0,0,0,.5);
      overflow: hidden;
      position: absolute;
      z-index: 999;
      height: 100%;
      transition: transform 1s, opacity .5s;
      transform: translateZ(1px);
    }

    .x-test-info:not(:hover) {
      transform: rotate(5deg) translateX(-100%) translateX(-10px) scaleY(.95) skewX(-1deg) skewY(-1deg) translateZ(1px);
      opacity: .6;
    }

    .dyslexia .x-test-info {
      background: #fafac8;
    }

    .x-test-name {
      margin: -1rem;
      margin-bottom: 1rem;
      padding: 1rem;
      background: #40596b;
      color: white;
    }

    .dyslexia .x-test-name {
      background: #dadaa8;
      color: black;
    }

    .x-button-container {
      display: flex;
      flex-direction: column;
      gap: .5rem;
    }

    .x-button {
      display: block;
      appearance: button;
      text-decoration: none;
      text-align: center;
      background-color: #f7cdcd;
      padding: 1rem 2rem;
      color: black;
      border-radius: .33rem;
      font-size: 1.5rem;
    }

    .x-button:hover {
      text-decoration: inherit;
      color: inherit;
    }

    .dyslexia .x-button {
      background: #dadaa8;
    }
  `;

  //use layer if possible on newer browsers to override important
  styleCss = `
    ${ styleCss }
    @layer { ${styleCss} }
  `;

  //add css to page, using GM_addStyle if possible
  if (window.GM_addStyle) {
    window.GM_addStyle(styleCss);
  } else {
    const styleElement = document.createElement("style");
    styleElement.innerHTML = styleCss;
    document.querySelector("head").append(styleElement);
  }
}

async function main() {
  applyStyles();
  loadSessionInfo().then(() => {
    displayUi();
  });
}

main();