Skip to content

Instantly share code, notes, and snippets.

@owatan
Last active November 22, 2024 14:59
Show Gist options
  • Save owatan/f6cf6c0d54cedc17415707627d43064a to your computer and use it in GitHub Desktop.
Save owatan/f6cf6c0d54cedc17415707627d43064a to your computer and use it in GitHub Desktop.
add link to SDVX VI official site to Vaddict (use tampremonkey)
// ==UserScript==
// @name SDVX6 official to Vaddict
// @namespace http://twitter.com/@pj_nawato
// @version 2024-11-23
// @description add link from SDVX6 official web site to Vaddict
// @author @owatan_jp
// @match https://p.eagate.573.jp/game/sdvx/vi/playdata/profile/index.html
// @match https://p.eagate.573.jp/game/sdvx/vi/playdata/rival/profile.html?rival_id=SV-*
// @icon https://vaddict.b35.jp/favicon.ico
// @grant GM_xmlhttpRequest
// @updateURL https://gist.github.com/owatan/f6cf6c0d54cedc17415707627d43064a.js
// @downloadURL https://gist.github.com/owatan/f6cf6c0d54cedc17415707627d43064a.js
// @supportURL https://gist.github.com/owatan/f6cf6c0d54cedc17415707627d43064a.js
// ==/UserScript==
(function() {
'use strict';
// #player_id 要素を取得
const playerElement = document.querySelector('#player_id');
if (playerElement) {
// 要素内のテキストを取得
const playerId = playerElement.textContent.trim();
if (playerId) {
const vaddict_url = `https://vaddict.b35.jp/user.php?player_id=${encodeURIComponent(playerId)}`;
// GM_xmlhttpRequest を使ってリクエストを送信
GM_xmlhttpRequest({
method: "GET",
url: vaddict_url,
onload: function(response) {
// HTTP ステータスコードの確認
if (response.status === 404) {
console.log(`404 Not Found: ${vaddict_url}`);
// 404 の場合の処理
const link_text = `<p style="color: orange;">This player does not use Vaddict.</p>`;
const insert = document.querySelector("#player_id");
insert.insertAdjacentHTML("beforeend", link_text);
} else {
console.log(`Response Status: ${response.status}`);
// 404 以外の場合の処理
const link_text = `<p><a style="color: orange;" href=${vaddict_url}>show Vaddict</a></p>`;
const insert = document.querySelector("#player_id");
insert.insertAdjacentHTML("beforeend", link_text);
}
},
onerror: function() {
console.error('リクエストに失敗しました。');
}
});
} else {
console.error('#player_id のテキストが空です。');
}
} else {
console.error('#player_id 要素が見つかりません。');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment