Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  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
  8. // @downloadURL http://ghux.altervista.org/UserScripts/KoL_AnyTopMenuIcon.user.js
  9. // @include http://www.kingdomofloathing.com/awesomemenu.php
  10. // @include http://127.0.0.1:*/awesomemenu.php
  11. // @include http://localhost:*/awesomemenu.php
  12. // @icon http://images.kingdomofloathing.com/itemimages/scroll1.gif
  13. // ==/UserScript==
  14.  
  15. function changeIcon() {
  16. var imgname = prompt("Input any image filename. (The last bit of the image URL: \nhttp://images.kingdomofloathing.com/\nitemimages/THIS_BIT_HERE.gif )", "seasidetown");
  17.  
  18. if (imgname !== null) { //If the user didn't cancel
  19.  
  20. var imgIsValid = false;
  21. while (!imgIsValid && imgname !== null) { //Keep asking until they input a proper image or give up
  22. imgname = imgname.trim();
  23. if (imgname.slice(0, 4) === "http") {
  24. 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);
  25. } else if (~imgname.indexOf("/")) {
  26. 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);
  27. } else if (~imgname.search(/[^\w.]/)) {
  28. imgname = prompt("Non-alphanumeric character detected.\n\nIf you know the filename is correct, please message CheesCake (#1995992) to fix this script.", imgname);
  29. } else {
  30. imgIsValid = true;
  31. }
  32. }
  33.  
  34. if (imgname !== null) { //Check again since we could have canceled in the while loop
  35. var period = imgname.indexOf("."); //If it has a file extension, the index of where it begins
  36. if (~period) { //If it has a file extension
  37. iconimg.src = "//images.kingdomofloathing.com/itemimages/" + imgname;
  38. iconinput.value = imgname.slice(0, period);
  39. } else { //If it doesn't have a file extension
  40. iconimg.src = "//images.kingdomofloathing.com/itemimages/" + imgname + ".gif";
  41. iconinput.value = imgname;
  42. }
  43. }
  44. }
  45. }
  46.  
  47. var iconimg = document.getElementsByClassName("icon")[0].children[2];
  48. var iconinput = document.getElementsByClassName("icon")[0].children[5];
  49. iconimg.addEventListener("click", changeIcon, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement