Created
April 6, 2018 16:44
-
-
Save tidusx18/91e8f0a6e9fa0e765c3a0eb98c9cd135 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 Canvas TinyMCE Update Contextual Links | |
// @namespace https://github.com/tidusx18 | |
// @version 0.0.1 | |
// @match https://fiu.instructure.com/*/pages/*/edit | |
// @grant none | |
// @noframes true | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function contexualizeLinks() { | |
window.addEventListener('load', function(event) { | |
tinymce.on('AddEditor', function(e) { | |
e.editor.on('init', function(editor) { | |
// setTimeout( function() { | |
// console.log(tinymce.activeEditor); | |
let listItems = tinymce.activeEditor.dom.select('li'); | |
for(let item of listItems) { | |
let a = tinymce.activeEditor.dom.select('a', item)[0]; | |
// console.log(a); | |
if(item.innerText.includes('http')) { | |
// console.log(item.innerText); | |
let itemContent = item.innerText.replace(/ +-\Whttp.+$/ig, ''); | |
// console.log(itemContent); | |
tinymce.activeEditor.dom.setHTML(a, itemContent); | |
tinymce.activeEditor.dom.setHTML(item, tinymce.DOM.getOuterHTML(a)); | |
} | |
} | |
// }, 2000 ); | |
}); | |
}); | |
}); | |
} | |
try { | |
contexualizeLinks(); | |
} catch(err) { | |
console.log('TinyMCE is not defined on this page.'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment