Feature - Implemented Add mall/wiki search links to item right-click menu

five35

New member
The wiki didn't specify where in the forum to post contributed code, and I didn't see anywhere obvious, but hopefully I've at least chosen somewhere sane. :)

This patch adds a new browser script to the relay browser, which extends KoL's pop-up item right-click menu ("ircm"). On pages which use the ircm, links for searching the mall (if the item is mallable) and the KoL Wiki are added to it.

hDCDd5B.png
G6WkhH6.png


Code:
Index: src/net/sourceforge/kolmafia/KoLConstants.java
===================================================================
--- src/net/sourceforge/kolmafia/KoLConstants.java	(revision 15584)
+++ src/net/sourceforge/kolmafia/KoLConstants.java	(working copy)
@@ -436,6 +436,7 @@
 	public static final String CLI_HTML = "cli.html";
 	public static final String COMBATFILTER_JS = "combatfilter.1.js";
 	public static final String HOTKEYS_JS = "hotkeys.js";
+	public static final String IRCM_JS = "ircm_extend.js";
 	public static final String MACROHELPER_JS = "macrohelper.3.js";
 	public static final String ONFOCUS_JS = "onfocus.1.js";
 	public static final String SORTTABLE_JS = "sorttable.2.js";
@@ -451,6 +452,7 @@
 		CLI_HTML,
 		COMBATFILTER_JS,
 		HOTKEYS_JS,
+		IRCM_JS,
 		MACROHELPER_JS,
 		ONFOCUS_JS,
 		SORTTABLE_JS,
Index: src/net/sourceforge/kolmafia/RequestEditorKit.java
===================================================================
--- src/net/sourceforge/kolmafia/RequestEditorKit.java	(revision 15584)
+++ src/net/sourceforge/kolmafia/RequestEditorKit.java	(working copy)
@@ -598,6 +598,7 @@
 		RequestEditorKit.addFolioLink( buffer );
 		RequestEditorKit.addNewLocationLinks( buffer );
 		RequestEditorKit.suppressPotentialMalware( buffer );
+		RequestEditorKit.extendRightClickMenu( buffer );
 
 		// Now do anything which doesn't work in Java's internal HTML renderer
 
@@ -701,6 +702,13 @@
 		}
 	}
 
+	private static final void extendRightClickMenu(StringBuffer buffer) {
+		if ( buffer.indexOf( "pop_ircm_contents" ) != -1 )
+		{
+			StringUtilities.insertBefore( buffer, "</html>", "<script src=\"/" + KoLConstants.IRCM_JS + "\"></script>" );
+		}
+	}
+
 	private static final String TOPMENU_REFRESH = "<script>top.menupane.location.href=\"topmenu.php\";</script>";
 	public static final void addTopmenuRefresh( final StringBuffer buffer )
 	{
Index: src/relay/ircm_extend.js
===================================================================
--- src/relay/ircm_extend.js	(revision 0)
+++ src/relay/ircm_extend.js	(working copy)
@@ -0,0 +1,29 @@
+(function(window) {
+	var WIKI_URL = "http://kol.coldfront.net/thekolwiki/index.php/Special:Search?go=Go&search=";
+
+	var SEARCH_HTML = "<div style='width:100%; padding-bottom: 3px;'><b>Search:</b> ";
+	var MALL_HTML = "<a href='/mall.php?pudnuggler=%NAME' class='small'>[mall]</a> ";
+	var WIKI_HTML = "<a target='_blank' href='" + WIKI_URL + "%NAME' class='small'>[wiki]</a></div>";
+
+	var original_function = window.pop_ircm_contents;
+
+	window.pop_ircm_contents = function(i, some) {
+		var original = original_function(i, some);
+		var name = $("[rel^='id=" + i.id + "&'] b").eq(0).text();
+
+		if (name) {
+			var html = SEARCH_HTML;
+
+			// mallable == !quest && !gift && tradeable
+			if (i.q == 0 && i.g == 0 && i.t == 1) {
+				html += MALL_HTML;
+			}
+
+			html += WIKI_HTML;
+
+			return [original[0] + html.replace(/%NAME/g, encodeURIComponent(name)), original[1] + 1];
+		}
+
+		return original;
+	}
+})(this);
 

Attachments

  • ircm_extend.patch
    2.9 KB · Views: 42
Top