Created
February 4, 2015 19:41
-
-
Save bmccormack/ba181471972f83738133 to your computer and use it in GitHub Desktop.
Add "Edit this article" links to Help Scout docs. You need to edit the docsID value first.
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 Help Scout - Add Edit Links to Articles | |
// @namespace http://your.help.site.com | |
// @include http://your.help.site.com/article/* | |
// @description Inserts Edit this article links in the top right of Help Scout support articles | |
// @author Ben McCormack | |
// @version 1.0.0.0 | |
// ==/UserScript== | |
//You need to insert the 24 digit hexadecimal docsID below in the doSomething() function. | |
//You can get that number by looking at the URL when editing a doc in help scout. | |
// New method to inject javascript | |
var script = document.createElement("script"); | |
script.textContent = "(" + js.toString() + ")();"; | |
document.body.appendChild(script); | |
// Repeat the method to inject css | |
var style = document.createElement("style"); | |
style.setAttribute('type', 'text/css'); | |
style.textContent = css(); | |
document.body.appendChild(style); | |
function js() { | |
init(); | |
function init() { | |
doSomething(); | |
} | |
function doSomething() { | |
//Get the docsID value from the URL when editing an article in Help Scout | |
var docsID = ''; | |
var baseURL = 'https://secure.helpscout.net/docs/' + docsID +'/article/' | |
var re = /http:\/\/.*\/article\/(\d*)(-|$)/ | |
matches = document.URL.match(re) | |
//Make sure we have a match for the number | |
if (matches.length < 1){ return; } | |
var articleNumber = matches[1] | |
var fullURL = baseURL + articleNumber | |
$('.title').before('<a class="edit-link" href="' + fullURL + '" target="_blank">Edit this article</a>') | |
console.log(fullURL); | |
} | |
} | |
function css() { | |
// Custom CSS goes here | |
var css = '.edit-link {\ | |
color: #C6C6C6 !important; \ | |
position: absolute; \ | |
right: 15px; \ | |
top: 15px; }'; | |
return css; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment