AtCoder Bookmarks

try to take over the world!

目前為 2021-02-03 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AtCoder Bookmarks
// @namespace    http://tampermonkey.net/
// @version      0.1
// @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");
    localStorage.setItem("atcoder", 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" 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;
      }
    });
  }
})();