Last active
February 10, 2019 06:44
-
-
Save isnot/8818dc9f330a64d36729058de0de0b2d to your computer and use it in GitHub Desktop.
IITCのデータを救出!旧URLからデータを取り出します。https://www.ingress.com/ を開いて、「Rescue!!」ボタンを押す
This file contains 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 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); | |
})(); |
Author
isnot
commented
Feb 10, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment