Last active
November 22, 2024 14:59
-
-
Save owatan/f6cf6c0d54cedc17415707627d43064a to your computer and use it in GitHub Desktop.
add link to SDVX VI official site to Vaddict (use tampremonkey)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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