Last active
August 8, 2018 21:59
-
-
Save anka-213/5252625980184bf596dd1839fd5e0f4b to your computer and use it in GitHub Desktop.
Add copy-button to http://lol.item-set.com/#!/editor
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 Copy LOL item-set | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Adds a button for copying the item set. | |
// @author You | |
// @match http://lol.item-set.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function deepFilter(x) { | |
if (_.isArray(x)) { | |
return _.map(x,deepFilter); | |
} else if (_.isObject(x)) { | |
return _.chain(x).omit((i,y)=>y.startsWith("$")).mapObject(deepFilter).value(); | |
} else { | |
return x; | |
} | |
} | |
function copyItemSet() { | |
var scope = angular.element($("body>.ng-scope")).scope(); | |
var is = scope.set; | |
var hero_name = scope.set.champion; | |
var hero = +scope.champions[hero_name].key; | |
var outObject = { | |
title: is.title, | |
associatedMaps: [11], | |
associatedChampions: [hero], | |
blocks: is.blocks | |
}; | |
var result = JSON.stringify(deepFilter(outObject)); | |
if (copyText(result)) { | |
console.log("Suuccessfully copied"); | |
} else { | |
console.log("Failed to copy:", result); | |
} | |
} | |
function copyText(str) { | |
var ta = document.createElement("textarea"); | |
ta.innerText = str; | |
document.body.append(ta); | |
ta.select(); | |
var ans = document.execCommand("copy"); | |
document.body.removeChild(ta); | |
return ans; | |
} | |
function insertButton() { | |
var download_button = $("set-downloader"); | |
if (download_button.length===0) { | |
return setTimeout(insertButton,100); | |
} | |
var br = $("<br>").insertAfter(download_button); | |
var div = $('<div class="btn btn-success btn-block"><i class="fa fa-copy"></i> Copy</div>').insertAfter(br); | |
div.click(copyItemSet); | |
} | |
$( document ).ready(insertButton); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment