AtCoder Bookmarks

try to take over the world!

اعتبارا من 04-02-2021. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         AtCoder Bookmarks
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  try to take over the world!
// @author       You
// @match        https://atcoder.jp/contests/*/tasks/*
// @match        https://atcoder-bookmarks.oxyshower.xyz
// @match        http://localhost:3000/
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM.setValue
// @grant GM.getValue
// @grant GM_listValues
// @grant GM.deleteValue
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// ==/UserScript==

(function () {
  "use strict";

  const URL = location.href;
  if (URL.match("https://atcoder-bookmarks.oxyshower.xyz")) {
    let id = 0;
    let datalist = [];
    for (const key of GM_listValues()) {
      let username = "",
        problemname = "",
        problemurl,
        idx = 8;
      while (key[idx] != "$") username += key[idx++];
      idx++;
      while (key[idx] != "$") problemname += key[idx++];
      idx++;
      problemurl = key.substr(idx);
      datalist[id++] = {
        userName: username,
        problemName: problemname,
        problemUrl: problemurl,
      };
    }
    localStorage.removeItem("atcoder");
    // objectは保存できない -> 文字列で保存
    localStorage.setItem("atcoder", JSON.stringify(datalist));
    // console.log(JSON.stringify(datalist));
  } else {
    const userName = document
      .getElementsByClassName("dropdown-toggle")[1]
      .textContent.slice(10, -17);
    const problemUrl = location.href;
    const problemName = document
      .getElementsByClassName("h2")[0]
      .textContent.slice(4, -9);
    const value =
      "atcoder" + "$" + userName + "$" + problemName + "$" + problemUrl;

    let html =
      '<button type="button" style="border: none; outline: none; color: rgb(218, 200, 42); background-color: white;" class="Bookmark">☆</button>';
    $(".h2").append(html);

    let onoff = "off";
    for (const key of GM_listValues()) {
      if (key == value) {
        onoff = "on";
        $(".Bookmark").text("★");
      }
    }
    $(".Bookmark").click(function () {
      switch (onoff) {
        case "off":
          onoff = "on";
          $(".Bookmark").text("★");
          GM.setValue(value);
          break;
        case "on":
          onoff = "off";
          $(".Bookmark").text("☆");
          GM.deleteValue(value);
          break;
      }
    });
  }
})();