Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Przełączanie kolonii
- // @version 1.0
- // @include *hegira.com.pl/*
- // @copyright free
- // ==/UserScript==
- ("use strict");
- //ponowne wejscie w ul lub stocznię, jeśli zmiania była dokonana w ww
- if (localStorage.linkSU !== "0" && localStorage.linkSU !== undefined) {
- const temp = [...localStorage.linkSU].join("");
- localStorage.linkSU = "0";
- window.location.href = temp;
- }
- //lista nagłówków
- const arrOfH = [
- ["h2", " - Centrum Dowodzenia"],
- ["h3", "planeta: "],
- ["h3", "stacja badawcza: "],
- ["h3", "stacja graniczna: "],
- ["h3", "drzewo życia: "],
- ["h3", "habitat: "],
- ];
- //zapamiętuje pierwszą i ostatnią kolonię
- const ostatni = $('input[name="gdzie_zagladamy"]').siblings("button")[0]
- .innerHTML;
- const pierwszy = $('input[name="gdzie_zagladamy"]').siblings("button")[
- $('input[name="gdzie_zagladamy"]').siblings("button").length - 1
- ].innerHTML;
- //funkcja dodająca guziki
- const guziki = function (h, c) {
- $(`${h}:contains(${c})`).after(
- `${
- pierwszy ===
- $(
- `button:contains(${$(`${h}:contains(${c})`)[0]
- .innerHTML.replace(`${c}`, "")
- .replace(" (orbita)", "")})`
- )[0].innerHTML
- ? ""
- : `</button><button type="button" id ="poprz" name = "${h},${c}"><--</button>`
- }${
- ostatni ===
- $(
- `button:contains(${$(`${h}:contains(${c})`)[0]
- .innerHTML.replace(`${c}`, "")
- .replace(" (orbita)", "")})`
- )[0].innerHTML
- ? ""
- : `<button type="button" id ="nast"name = "${h},${c}">--></button>`
- }`
- );
- };
- //pętla sprawdzająca jaki jest nagłówek i odpalająca funkcje dodającą
- for (let i = 0; i < arrOfH.length; i++) {
- const [h, co] = arrOfH[i];
- if ($(`${h}:contains(${co})`).length) {
- guziki(h, co);
- }
- }
- //wcześniejsza
- $("button#poprz").click(function () {
- const [h, c] = this.name.split(",");
- if ($("h3:contains(Stoczniowiec: )").length > 0) {
- localStorage.linkSU = window.location.href;
- }
- $(
- `button:contains(${$(`${h}:contains(${c})`)[0]
- .innerHTML.replace(`${c}`, "")
- .replace(" (orbita)", "")})`
- )
- .parent()
- .parent()
- .parent()
- .next()
- .children()
- ?.children("form")
- .submit();
- });
- //następna
- $("button#nast").click(function () {
- const [h, c] = this.name.split(",");
- if ($("h3:contains(Stoczniowiec: )").length > 0) {
- localStorage.linkSU = window.location.href;
- }
- $(
- `button:contains(${$(`${h}:contains(${c})`)[0]
- .innerHTML.replace(`${c}`, "")
- .replace(" (orbita)", "")})`
- )
- .parent()
- .parent()
- .parent()
- .prev()
- .children()
- ?.children("form")
- .submit();
- });
Add Comment
Please, Sign In to add comment