Forked from unitycoder/UnityForumBoardSearchHelper.js
Last active
June 15, 2023 16:51
-
-
Save instance-id/737100c016acd206b399e90e3a907a27 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; | |
// To allow usage on forum category pages | |
// Ex. https://forum.unity.com/categories/ecs-for-unity.823/ | |
if (ref.includes("categories")) { | |
ref = ref.replace("https://forum.unity.com/categories/", ""); | |
} else if (ref.includes("forums")) { | |
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).replaceAll("-", " "); | |
// 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