Trambambaj

Przełączanie kolonii cd, ul, os z powrotem

Aug 16th, 2021 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       Przełączanie kolonii
  3. // @version    1.0
  4. // @include    *hegira.com.pl/*
  5. // @copyright  free
  6. // ==/UserScript==
  7. ("use strict");
  8. //ponowne wejscie w ul lub stocznię, jeśli zmiania była dokonana w ww
  9. if (localStorage.linkSU !== "0" && localStorage.linkSU !== undefined) {
  10.   const temp = [...localStorage.linkSU].join("");
  11.   localStorage.linkSU = "0";
  12.   window.location.href = temp;
  13. }
  14. //lista nagłówków
  15. const arrOfH = [
  16.   ["h2", " - Centrum Dowodzenia"],
  17.   ["h3", "planeta: "],
  18.   ["h3", "stacja badawcza: "],
  19.   ["h3", "stacja graniczna: "],
  20.   ["h3", "drzewo życia: "],
  21.   ["h3", "habitat: "],
  22. ];
  23. //zapamiętuje pierwszą i ostatnią kolonię
  24. const ostatni = $('input[name="gdzie_zagladamy"]').siblings("button")[0]
  25.   .innerHTML;
  26. const pierwszy = $('input[name="gdzie_zagladamy"]').siblings("button")[
  27.   $('input[name="gdzie_zagladamy"]').siblings("button").length - 1
  28. ].innerHTML;
  29. //funkcja dodająca guziki
  30. const guziki = function (h, c) {
  31.   $(`${h}:contains(${c})`).after(
  32.     `${
  33.       pierwszy ===
  34.       $(
  35.         `button:contains(${$(`${h}:contains(${c})`)[0]
  36.           .innerHTML.replace(`${c}`, "")
  37.           .replace(" (orbita)", "")})`
  38.       )[0].innerHTML
  39.         ? ""
  40.         : `</button><button type="button" id ="poprz" name = "${h},${c}"><--</button>`
  41.     }${
  42.       ostatni ===
  43.       $(
  44.         `button:contains(${$(`${h}:contains(${c})`)[0]
  45.           .innerHTML.replace(`${c}`, "")
  46.           .replace(" (orbita)", "")})`
  47.       )[0].innerHTML
  48.         ? ""
  49.         : `<button type="button" id ="nast"name = "${h},${c}">--></button>`
  50.     }`
  51.   );
  52. };
  53. //pętla sprawdzająca jaki jest nagłówek i odpalająca funkcje dodającą
  54. for (let i = 0; i < arrOfH.length; i++) {
  55.   const [h, co] = arrOfH[i];
  56.   if ($(`${h}:contains(${co})`).length) {
  57.     guziki(h, co);
  58.   }
  59. }
  60. //wcześniejsza
  61. $("button#poprz").click(function () {
  62.   const [h, c] = this.name.split(",");
  63.   if ($("h3:contains(Stoczniowiec: )").length > 0) {
  64.     localStorage.linkSU = window.location.href;
  65.   }
  66.  
  67.   $(
  68.     `button:contains(${$(`${h}:contains(${c})`)[0]
  69.       .innerHTML.replace(`${c}`, "")
  70.       .replace(" (orbita)", "")})`
  71.   )
  72.     .parent()
  73.     .parent()
  74.     .parent()
  75.     .next()
  76.     .children()
  77.     ?.children("form")
  78.     .submit();
  79. });
  80. //następna
  81. $("button#nast").click(function () {
  82.   const [h, c] = this.name.split(",");
  83.   if ($("h3:contains(Stoczniowiec: )").length > 0) {
  84.     localStorage.linkSU = window.location.href;
  85.   }
  86.  
  87.   $(
  88.     `button:contains(${$(`${h}:contains(${c})`)[0]
  89.       .innerHTML.replace(`${c}`, "")
  90.       .replace(" (orbita)", "")})`
  91.   )
  92.     .parent()
  93.     .parent()
  94.     .parent()
  95.     .prev()
  96.     .children()
  97.     ?.children("form")
  98.     .submit();
  99. });
  100.  
Add Comment
Please, Sign In to add comment