|
// ==UserScript== |
|
// @name Jump directly to Edit view of BC Newsletter Templates |
|
// @namespace https://gist.github.com/r-k-b/ |
|
// @version 1.0.0 |
|
// @description Adds links to the 'Template' tab of the 'Email Campaign' editor UI on Business Catalyst sites, that open the Partner Portal 'Edit Template' UI in a new tab/window. Only fires when HTTPS is enabled. |
|
// @author Robert K. Bell |
|
// @homepage https://gist.github.com/r-k-b/2027da639ed6d00eadb6202d7b8391a2 |
|
// @downloadURL https://gist.github.com/r-k-b/2027da639ed6d00eadb6202d7b8391a2/raw/link-direct-to-pp-newsletter.user.js |
|
// @match https://*.worldsecuresystems.com/Admin/Campaigns_Details.aspx* |
|
// @grant none |
|
// @run-at document-idle |
|
// ==/UserScript== |
|
|
|
/* jshint esnext: true */ |
|
|
|
(function(){ |
|
|
|
const templates = document.querySelectorAll('.template[data-option-value]') |
|
|
|
function extractTemplateIDFromValue(value) { |
|
return value.split('|')[0]; |
|
} |
|
|
|
/** |
|
* <http://stackoverflow.com/a/35385518/2014893> |
|
* @param {String} HTML representing a single element |
|
* @return {Element} |
|
*/ |
|
function htmlToElement(html) { |
|
var template = document.createElement('template'); |
|
template.innerHTML = html; |
|
return template.content.firstChild; |
|
} |
|
|
|
/** |
|
* @param {String} HTML representing any number of sibling elements |
|
* @return {NodeList} |
|
*/ |
|
function htmlToElements(html) { |
|
var template = document.createElement('template'); |
|
template.innerHTML = html; |
|
return template.content.childNodes; |
|
} |
|
|
|
function modifyUI(elem){ |
|
const templateID = extractTemplateIDFromValue(elem.dataset.optionValue) |
|
if (!templateID || templateID === 'None') { |
|
return; |
|
} |
|
const ppUrl = `http://ava-next.worldsecuresystems.com/PartnerPortal/Utilities/AddNewsletterTemplate.aspx?A=CEDIT&CID=${ templateID }`; |
|
|
|
const ppLink = `<a target='_blank' href='${ ppUrl }'>Show In Partner Portal 🗗</a>` |
|
|
|
const ppLinkElem = htmlToElement(ppLink); |
|
|
|
console.info({ppLinkElem, ppUrl, elem}) |
|
|
|
elem.insertBefore(ppLinkElem, null) |
|
|
|
// ppLinkElems.forEach(link => { |
|
// console.info({link}) |
|
// elem.insertBefore(link, null) |
|
// }); |
|
} |
|
|
|
templates.forEach(modifyUI) |
|
|
|
})(); |