Last active
January 6, 2020 07:08
-
-
Save Sneezry/1d4d60c9375289d8c7042f403227b4ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Azure DevOps Wiki Search | |
// @namespace http://lizhe.net/ | |
// @version 0.1 | |
// @description Press to search entire Wiki | |
// @author Zhe Li | |
// @match https://*.visualstudio.com/*/_wiki/wikis/* | |
// @match https://dev.azure.com/*/*/_wiki/wikis/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
main(Date.now()); | |
})(); | |
function main(startTime) { | |
var filterInputbox = document.getElementById('__bolt-textfield-input-1'); | |
if (!filterInputbox) { | |
if (Date.now() - startTime < 5000) { | |
setTimeout(() => { main(startTime); }, 100); | |
} | |
return; | |
} | |
var wikiUriMatches = location.href.match(/visualstudio.com\/(.*?)\/_wiki\/wikis\/(.*?)\//); | |
if (!wikiUriMatches) { | |
wikiUriMatches = location.href.match(/dev.azure.com\/(.*?)\/_wiki\/wikis\/(.*?)\//); | |
} | |
var projectName = wikiUriMatches[1]; | |
var wikiName = wikiUriMatches[2]; | |
var outer = filterInputbox.parentElement; | |
var filterIcon = outer.getElementsByClassName('ms-Icon--Filter')[0]; | |
if (filterIcon) { | |
filterIcon.className = 'keyword-filter-icon prefix bolt-textfield-icon bolt-textfield-no-text flex-noshrink fabric-icon ms-Icon--Search'; | |
} | |
var form = document.createElement('form'); | |
form.style.width = '100%'; | |
form.target = '_blank'; | |
form.action = `/${projectName}/_search`; | |
var typeInputbox = document.createElement('input'); | |
typeInputbox.name = 'type'; | |
typeInputbox.type = 'hidden'; | |
typeInputbox.value = 'wiki'; | |
var wikiFilterInputbox = document.createElement('input'); | |
wikiFilterInputbox.name = 'filters'; | |
wikiFilterInputbox.type = 'hidden'; | |
wikiFilterInputbox.value = `Wiki{${wikiName}}`; | |
filterInputbox.style.width = '100%'; | |
filterInputbox.name = 'text'; | |
filterInputbox.placeholder = 'Filter by title, press enter to search'; | |
filterInputbox.onkeydown = (evt) => { | |
if (evt.keyCode === 13 && filterInputbox.value.trim()) { | |
form.submit(); | |
} | |
}; | |
form.appendChild(typeInputbox); | |
form.appendChild(wikiFilterInputbox); | |
form.appendChild(filterInputbox); | |
outer.appendChild(form); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment