您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
A UserScript helps import teams to a Falinks Teambuilder room
当前为
// ==UserScript== // @name falinks-teambuilder-helper // @description A UserScript helps import teams to a Falinks Teambuilder room // @namespace http://tampermonkey.net/ // @version 0.0.2 // @author txfs19260817 // @icon https://www.falinks-teambuilder.com/favicon.ico // @source https://github.com/txfs19260817/falinks-teambuilder-helper // @license WTFPL // @match http*://play.pokemonshowdown.com/* // @match http*://*.psim.us/* // @match http*://pokepast.es/* // @require https://unpkg.com/@pkmn/sets/build/production.min.js // @connect www.falinks-teambuilder.com // @run-at document-end // ==/UserScript== /******/ (() => { // webpackBootstrap /******/ "use strict"; var __webpack_exports__ = {}; ;// CONCATENATED MODULE: external "window" const external_window_namespaceObject = window; ;// CONCATENATED MODULE: ./src/index.ts const pokepasteURL = "pokepast.es"; const createRoomButtonId = "falinks-new-room-btn"; function S4() { return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1); } function falinksRoomEndpoint(packed) { return `//www.falinks-teambuilder.com/room/room_${S4()}${S4()}/?protocol=WebSocket&packed=${encodeURIComponent(packed)}`; } function pasteToPacked(paste) { var ref; // pkmnSets.Teams is available in dev, // whereas `pkmnSets.PokemonTeams` is equivalent to `window.PokemonTeams` exported in prod //@ts-ignore const teams = external_window_namespaceObject.Teams ?? external_window_namespaceObject.PokemonTeams; return ((ref = teams.importTeam(paste)) === null || ref === void 0 ? void 0 : ref.pack()) ?? ''; } function createRoomButton(packed) { const submitBtn = document.createElement("button"); submitBtn.id = createRoomButtonId; submitBtn.textContent = "🤝 Open in a Falinks Teambuilder room"; submitBtn.type = "button"; submitBtn.onclick = ()=>{ window.open(falinksRoomEndpoint(packed)); }; // pokepast.es potentially erased all css, including button Object.assign(submitBtn.style, { outline: "none", cursor: "pointer", textAlign: "center", textDecoration: "none", boxShadow: "0 1px 2px rgba(0,0,0,.2),inset 0 -1px 2px #fff", borderRadius: "5px", fontFamily: "Verdana,Helvetica,Arial,sans-serif", display: "inline-block", color: "#222", textShadow: "0 1px 0 #fff", border: "1px solid #aaa", background: "linear-gradient(to bottom,#f6f6f6,#e3e3e3)", fontSize: "9pt", padding: "3px 8px", marginLeft: "6px", marginBottom: "3px" }); return submitBtn; } function getPasteAtPokepaste() { return [ 1, 2, 3, 4, 5, 6 ].map((i)=>{ var ref; return ((ref = document.querySelector(`body > article:nth-child(${i}) > pre`)) === null || ref === void 0 ? void 0 : ref.textContent) ?? ''; }).join(''); } function getPackedAtShowdown() { var ref, ref1; // @ts-ignore return ((ref = unsafeWindow.room) === null || ref === void 0 ? void 0 : (ref1 = ref.curTeam) === null || ref1 === void 0 ? void 0 : ref1.team) ?? ''; } function addPackedToLocalStorage(packedTeam) { const updatedShowdownTeams = packedTeam + "\n" + localStorage.getItem("showdown_teams"); localStorage.setItem("showdown_teams", updatedShowdownTeams); } function main() { const { host , hash } = window.location; if (host === pokepasteURL) { const paste = getPasteAtPokepaste(); const packed = pasteToPacked(paste); const btn = createRoomButton(packed); document.querySelector("body > aside").append(btn); } else { // add the button to Showdown Teambuilder, next to "Upload to PokePaste" button const observer = new MutationObserver(function() { const pokepasteForm = document.getElementById("pokepasteForm"); if (pokepasteForm && !document.getElementById(createRoomButtonId)) { const packed = getPackedAtShowdown(); const btn = createRoomButton(packed); pokepasteForm.appendChild(btn); } }); observer.observe(document.querySelector("body"), { subtree: true, childList: true }); // check both referer and hash to find if a packed team sent from Falinks Teambuilder if (hash && document.referrer.includes("falinks-teambuilder")) { const packedTeam = decodeURIComponent(document.location.hash.slice(1)); const doAdd = confirm("Would you like to add this team from Falinks teambuilder to your teams?\n" + packedTeam); if (doAdd) { addPackedToLocalStorage(packedTeam); history.replaceState(null, document.title, location.pathname + location.search); window.location.reload(); } } } } main(); /******/ })() ;