Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name KoL Any Top Menu Icon
- // @namespace http://www.kingdomofloathing.com/showplayer.php?who=1995992
- // @author CheesCake (#1995992)
- // @description Adds a right-click option to the topmenu icon selector to allow you to use any KoL item image as an icon.
- // @version 1
- // @downloadURL http://ghux.altervista.org/UserScripts/KoL_AnyTopMenuIcon.user.js
- // @include http://www.kingdomofloathing.com/awesomemenu.php
- // @include http://127.0.0.1:*/awesomemenu.php
- // @include http://localhost:*/awesomemenu.php
- // @icon http://images.kingdomofloathing.com/itemimages/scroll1.gif
- // ==/UserScript==
- function changeIcon() {
- var imgname = prompt("Input any image filename. (The last bit of the image URL: \nhttp://images.kingdomofloathing.com/\nitemimages/THIS_BIT_HERE.gif )", "seasidetown");
- if (imgname !== null) { //If the user didn't cancel
- var imgIsValid = false;
- while (!imgIsValid && imgname !== null) { //Keep asking until they input a proper image or give up
- imgname = imgname.trim();
- if (imgname.slice(0, 4) === "http") {
- imgname = prompt("Filename not valid. Don't include the whole URL, just the bit after the last /.\n ( http://images.kingdomofloathing.com/itemimages/THIS_BIT_HERE.gif )\n Note that off-site images will not work.", imgname);
- } else if (~imgname.indexOf("/")) {
- imgname = prompt("Filename not valid. Don't include the whole path, just the bit after the last /.\n ( http://images.kingdomofloathing.com/itemimages/THIS_BIT_HERE.gif )\n Note that only images in /itemimages/ can be used.", imgname);
- } else if (~imgname.search(/[^\w.]/)) {
- imgname = prompt("Non-alphanumeric character detected.\n\nIf you know the filename is correct, please message CheesCake (#1995992) to fix this script.", imgname);
- } else {
- imgIsValid = true;
- }
- }
- if (imgname !== null) { //Check again since we could have canceled in the while loop
- var period = imgname.indexOf("."); //If it has a file extension, the index of where it begins
- if (~period) { //If it has a file extension
- iconimg.src = "//images.kingdomofloathing.com/itemimages/" + imgname;
- iconinput.value = imgname.slice(0, period);
- } else { //If it doesn't have a file extension
- iconimg.src = "//images.kingdomofloathing.com/itemimages/" + imgname + ".gif";
- iconinput.value = imgname;
- }
- }
- }
- }
- var iconimg = document.getElementsByClassName("icon")[0].children[2];
- var iconinput = document.getElementsByClassName("icon")[0].children[5];
- iconimg.addEventListener("click", changeIcon, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement