AtCoderTags_Hint

AtCoderの問題ページにカテゴリーを知ることの出来るボタンを設置します。

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.

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

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

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

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

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

// ==UserScript==
// @name         AtCoderTags_Hint
// @version      0.9
// @author       Null_Null
// @match        https://atcoder.jp/contests/*/tasks/*
// @match        https://*/tasks/*
// @grant        none
// @namespace    https://github.com/null-null-programming/AtCoderTags-Helper
// @description  AtCoderの問題ページにカテゴリーを知ることの出来るボタンを設置します。
// ==/UserScript==

function getContestName() {
  let contestURL = location.href;
  let contestArray = contestURL.split('/');
  return contestArray[contestArray.length - 1];
}

$('#contest-nav-tabs').prepend(`<div>
    <div id="tag-badge" class="row">
      <button id="tags-hint" type="button" class="btn btn-info">Tag</button>
      <span id="hint-tag-0" class="col badge badge-pill badge-primary"></span>
      <span id="hint-tag-1" class="col badge badge-pill badge-primary"></span>
      <span id="hint-tag-2" class="col badge badge-pill badge-primary"></span>
      <span id="hint-tag-3" class="col badge badge-pill badge-primary"></span>
    </div>
</div>`);

$('#tags-hint').click(function() {
    getTag();
})

async function getTag() {
    let parser = new DOMParser();
    let archiveDom = parser.parseFromString((await $.get('https://atcoder-tags.herokuapp.com/check/'+getContestName())), "text/html");
    let tag_list=[];
    if(archiveDom.querySelector("#tag0")!=null)tag_list.push(archiveDom.querySelector("#tag0").innerText);
    if(archiveDom.querySelector("#tag1")!=null)tag_list.push(archiveDom.querySelector("#tag1").innerText);
    if(archiveDom.querySelector("#tag2")!=null)tag_list.push(archiveDom.querySelector("#tag2").innerText);
    if(archiveDom.querySelector("#tag3")!=null)tag_list.push(archiveDom.querySelector("#tag3").innerText);

    if(tag_list[0]!='None'){
        $('#hint-tag-0').html(tag_list[0]);
    }
    if(tag_list[1]!='None' && tag_list[1]!=tag_list[0]){
        $('#hint-tag-1').html(tag_list[1]);
    }
    if(tag_list[2]!='None' && tag_list[2]!=tag_list[0]){
        $('#hint-tag-2').html(tag_list[2]);
    }
    if(tag_list[3]!='None' && tag_list[3]!=tag_list[0]){
        $('#hint-tag-3').html(tag_list[3]);
    }

    return;
}