-
-
Save isnot/8818dc9f330a64d36729058de0de0b2d to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name rescue-iitc-data.user.js | |
// @namespace https://plus.google.com/+いしだなおと | |
// @version 0.1 | |
// @description To Extract IITC Data from localStorage | |
// @author isnot | |
// @match https://www.ingress.com/ | |
// @grant none | |
// ==/UserScript== | |
// * 処理を開始するためのボタンを配置する | |
// * メインのウインドウを表示する | |
// ** localStorageのキーを列挙 | |
// * 指定したキーの値を取り出して、画面に表示 | |
(function () { | |
'use strict'; | |
// 主なプラグインの、バックアップしたいキー | |
const well_known_keys = { | |
'iitc-plugin-fusen' : '★ Fusen', | |
'plugin-bookmarks' : '★ Bookmarks (plugin-bookmarks)', | |
'plugin-draw-tools-layer' : '★ Draw Tools', | |
'plugin-keys-data' : '★ Keys (plugin-keys-data)', | |
}; | |
const listUpKeys = () => { | |
let keyNames = {}; | |
const keys_a = Object.keys(localStorage); | |
keys_a.forEach((k) => { | |
if (localStorage.hasOwnProperty(k)) { | |
keyNames[k] = k; | |
} | |
}); | |
Object.keys(well_known_keys).forEach((w) => { | |
keyNames[w] = well_known_keys[w]; | |
}); | |
console.log(keyNames); // DEBUG | |
return keyNames; | |
}; | |
const getFormSelect = () => { | |
const form = document.createElement('form'); | |
const select = document.createElement('select'); | |
select.id = 'keySelect'; | |
const items = listUpKeys(); | |
Object.keys(items).forEach((name) => { | |
const option = document.createElement('option'); | |
option.value = name; | |
const label = document.createTextNode(items[name]); | |
option.appendChild(label); | |
select.appendChild(option); | |
}); | |
select.addEventListener('change', changeKey, false); | |
form.appendChild(select); | |
return form; | |
}; | |
const setupDialog = () => { | |
const div = document.createElement('div'); | |
div.textContent = 'あらゆる意味で無保証です!'; | |
const form = getFormSelect(); | |
div.appendChild(form); | |
const div_data = document.createElement('div'); | |
div_data.id = 'dataArea'; | |
div.appendChild(div_data); | |
div_data.style.border = '2px black solid'; | |
div_data.style.padding = '5px'; | |
const body = document.evaluate('//*[@id="site"]/footer/div[2]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
body.snapshotItem(0).appendChild(div); | |
}; | |
const changeKey = (e) => { | |
const select = document.getElementById('keySelect'); | |
const idx = select.selectedIndex; | |
const area = document.getElementById('dataArea'); | |
try { | |
const key = select.options[idx].value; | |
area.textContent = localStorage.getItem(key); | |
} catch (e) { | |
console.log( 'Error: ' + e ); | |
} | |
}; | |
// 処理開始するボタンを設置 | |
const key_node = document.evaluate('//*[@id="site"]/footer', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
const new_div = document.createElement('div'); | |
new_div.className = 'footer__container'; | |
new_div.setAttribute('style', 'background:#fff;color:#000;'); | |
const alink = document.createElement('button'); | |
alink.addEventListener('click', setupDialog, false); | |
alink.textContent = 'Rescue!!'; | |
new_div.appendChild(alink); | |
key_node.snapshotItem(0).appendChild(new_div); | |
//console.log(key_node.snapshotItem(0).textContent); | |
})(); |
LICENSE
MIT License
Copyright (c) 2018 ISHIDA Naoto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
参考:使用イメージ
※Rawが見えないときは、PC版サイトに切り替える
新URLでインテルマップを開いてから、アプリケーション→ローカルストレージ、と辿って、同名の要素に上書きする