Last active
August 15, 2023 17:39
-
-
Save thisnameissoclever/06e5ac65817e7a9fb7395d8dc4d29a83 to your computer and use it in GitHub Desktop.
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
(function openLatestPageVersion() { | |
var originalURL, pageNameIndex, pageNameEndIndex, pageName, latestURL; | |
originalURL = location.href; | |
if (!originalURL.toString().includes('docs.servicenow.com')) { | |
alert('This does not appear to be a ServiceNow Docs page. This button only works for pages on docs.servicenow.com.'); | |
return; | |
} | |
pageNameIndex = (originalURL.indexOf('/concept/') + 9); | |
pageNameEndIndex = (originalURL.indexOf('.html', pageNameIndex) + 5); | |
pageName = originalURL.substring(pageNameIndex, pageNameEndIndex); | |
latestURL = 'https://docs.servicenow.com/csh?topicname=' + pageName + '&version=latest'; | |
navigator.clipboard.writeText(latestURL); | |
alert('Latest page URL copied to clipboard.\nNavigating to latest page version.'); | |
location.href = latestURL; | |
})(); | |
/* "Compiled" code that's actually in the bookmarklet below: | |
(function(){var a=location.href;if(a.toString().includes("docs.servicenow.com")){var b=a.indexOf("/concept/")+9;var c=a.indexOf(".html",b)+5;a="https://docs.servicenow.com/csh?topicname="+a.substring(b,c)+"&version=latest";navigator.clipboard.writeText(a);alert("Latest page URL copied to clipboard.\nNavigating to latest page version.");location.href=a}else alert("This does not appear to be a ServiceNow Docs page. This button only works for pages on docs.servicenow.com.")})(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Tim, this is really useful for me but it doesn't work if the docs URL doesn't contain the string '/concept/'
For example this URL fails and bombs: https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/csdm-implementation/task/csdm-enable-tso.html
So, I added a condition to handle it:
https://gist.github.com/Hoptimal/3339d1671d30940b9f793f996c2f658b
Hope it helps?