Last active
June 15, 2023 16:52
-
-
Save unitycoder/061b00201170399404a285175b2137dc to your computer and use it in GitHub Desktop.
Unity Forum Search : AutoSelect current board item inside Search select list (based on referrer url)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Unity Forum Search : AutoSelect current board item inside Search select list (based on referrer url) | |
// @namespace https://unitycoder.com | |
// @version 1 | |
// @include https://forum.unity.com/search/?type=post | |
// @grant none | |
// ==/UserScript== | |
// more info https://unitycoder.com/blog/2021/05/26/unity-forums-auto-select-current-subforum-in-search-greasemonkey-script/ | |
// get referring board url | |
if (document.referrer==null) return; | |
// cleanup ref | |
var ref = document.referrer; | |
ref = ref.replace("https://forum.unity.com/forums/",""); | |
// find board name from url | |
var dotPos = ref.indexOf('.'); | |
if (dotPos==-1) return; | |
ref = ref.substring(0,dotPos); | |
// get selection box that contains forum boards | |
var sel = document.getElementById("ctrl_nodes"); | |
// loop to find match in the select items and url board name | |
for (var i = 0;i<sel.options.length;i++) | |
{ | |
var item = sel.options[i].text.trim(); | |
if (item.toLowerCase() == ref.toLowerCase()) | |
{ | |
sel.selectedIndex = i; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This didn't work out of the gate for me in firefox, I had to make the following edit. After that, all was well.
https://gist.github.com/instance-id/737100c016acd206b399e90e3a907a27#file-unityforumboardsearchhelper-js-L20
Then also added the ability to be used from a 'categories' page