Torn Rackets

description

目前為 2019-09-04 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Torn Rackets
// @namespace    namespace
// @version      0.2
// @description  description
// @author       tos
// @match        *.torn.com/city.php*
// @grant        GM_addStyle
// @grant        GM_setClipboard
// ==/UserScript==

GM_addStyle(`
#x_button_right {
  background-color: #c13c3c;
  color: #eaeaea;
  cursor: pointer;
  padding: 1em;
  position: fixed;
  right: 0;
}
`)


$( document ).ajaxComplete(function(event, jqXHR, ajaxObj) {
  if (ajaxObj.url && ajaxObj.url.includes('step=mapData')) {
    const mapdata = JSON.parse(jqXHR.responseText)
    document.querySelector('div.content').insertAdjacentHTML('beforebegin', `<div id="x_button_right">Copy Rackets (${mapdata.rackets.length})</div>`)
    document.querySelector('#x_button_right').addEventListener('click', (e) => {
      let csv = ''
      mapdata.rackets.forEach(r => csv += r.type+'\t'+r.name+'\t'+r.description+'\n')
      GM_setClipboard(csv)
    })
  }
})