Skip to content

Instantly share code, notes, and snippets.

@anka-213
Last active August 8, 2018 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anka-213/5252625980184bf596dd1839fd5e0f4b to your computer and use it in GitHub Desktop.
Save anka-213/5252625980184bf596dd1839fd5e0f4b to your computer and use it in GitHub Desktop.
// ==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>&nbsp;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