SHOW:
|
|
- or go back to the newest paste.
1 | // ==UserScript== | |
2 | // @name KoL Any Top Menu Icon | |
3 | // @namespace http://www.kingdomofloathing.com/showplayer.php?who=1995992 | |
4 | // @author CheesCake (#1995992) | |
5 | // @description Adds a right-click option to the topmenu icon selector to allow you to use any KoL item image as an icon. | |
6 | // @version 1 | |
7 | - | // @updateURL http://ghux.altervista.org/UserScripts/KoL_AnyTopMenuIcon.user.js |
7 | + | |
8 | // @include http://www.kingdomofloathing.com/awesomemenu.php | |
9 | // @include http://127.0.0.1:*/awesomemenu.php | |
10 | // @include http://localhost:*/awesomemenu.php | |
11 | // @icon http://images.kingdomofloathing.com/itemimages/scroll1.gif | |
12 | // ==/UserScript== | |
13 | ||
14 | function changeIcon() { | |
15 | var imgname = prompt("Input any image filename. (The last bit of the image URL: \nhttp://images.kingdomofloathing.com/\nitemimages/THIS_BIT_HERE.gif )", "seasidetown"); | |
16 | ||
17 | if (imgname !== null) { //If the user didn't cancel | |
18 | ||
19 | var imgIsValid = false; | |
20 | while (!imgIsValid && imgname !== null) { //Keep asking until they input a proper image or give up | |
21 | imgname = imgname.trim(); | |
22 | if (imgname.slice(0, 4) === "http") { | |
23 | 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); | |
24 | } else if (~imgname.indexOf("/")) { | |
25 | 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); | |
26 | } else if (~imgname.search(/[^\w.]/)) { | |
27 | imgname = prompt("Non-alphanumeric character detected.\n\nIf you know the filename is correct, please message CheesCake (#1995992) to fix this script.", imgname); | |
28 | } else { | |
29 | imgIsValid = true; | |
30 | } | |
31 | } | |
32 | ||
33 | if (imgname !== null) { //Check again since we could have canceled in the while loop | |
34 | var period = imgname.indexOf("."); //If it has a file extension, the index of where it begins | |
35 | if (~period) { //If it has a file extension | |
36 | iconimg.src = "//images.kingdomofloathing.com/itemimages/" + imgname; | |
37 | iconinput.value = imgname.slice(0, period); | |
38 | } else { //If it doesn't have a file extension | |
39 | iconimg.src = "//images.kingdomofloathing.com/itemimages/" + imgname + ".gif"; | |
40 | iconinput.value = imgname; | |
41 | } | |
42 | } | |
43 | } | |
44 | } | |
45 | ||
46 | var iconimg = document.getElementsByClassName("icon")[0].children[2]; | |
47 | var iconinput = document.getElementsByClassName("icon")[0].children[5]; | |
48 | iconimg.addEventListener("click", changeIcon, false); |