// ==UserScript== // @name TinyMce for Evernote // @namespace https://github.com/Amourspirit/TinyMce-for-Evernote // @version 3.3.0 // @description Adds TinyMce in Evernote with custom options including source code. A new button is added to Evernote top toolbar section. // @author Paul Moss // @run-at document-end // @include /^https?:\/\/www\.evernote\.com\/home\.action.*n=.*$/ // @include /^https?:\/\/www\.evernote\.com\/u\/0/Home\.action.*n=.*$/ // @include /^https?:\/\/app\.yinxiang\.com\/Home\.action.*n=.*$/ // @include /^https?:\/\/app\.yinxiang\.com\/u\/0/Home\.action.*n=.*$/ // @match https://www.evernote.com/Home.action* // @match https://www.evernote.com/u/0/Home.action* // @match https://app.yinxiang.com/Home.action* // @match https://app.yinxiang.com/u/0/Home.action* // @noframes // @license MIT // @homepageURL https://amourspirit.github.io/TinyMce-for-Evernote/ // @update https://github.com/Amourspirit/TinyMce-for-Evernote/raw/master/dist/TinyMce_for_Evernote.user.js // @contributionURL https://amourspirit.github.io/TinyMce-for-Evernote/#donate // @require https://openuserjs.org/src/libs/sizzle/GM_config.min.js // @require https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js // @require https://cdn.jsdelivr.net/npm/jquery-xpath@0.3.1/jquery.xpath.js // @grant GM_registerMenuCommand // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function ($, tinymce) { 'use strict'; $ = $ && $.hasOwnProperty('default') ? $['default'] : $; var tinymce__default = 'default' in tinymce ? tinymce['default'] : tinymce; var PriorityLevel; (function (PriorityLevel) { PriorityLevel[PriorityLevel["none"] = 0] = "none"; PriorityLevel[PriorityLevel["now"] = 1] = "now"; PriorityLevel[PriorityLevel["med"] = 2] = "med"; PriorityLevel[PriorityLevel["high"] = 3] = "high"; })(PriorityLevel || (PriorityLevel = {})); var DebugLevel; (function (DebugLevel) { DebugLevel[DebugLevel["debug"] = 0] = "debug"; DebugLevel[DebugLevel["error"] = 1] = "error"; DebugLevel[DebugLevel["warn"] = 2] = "warn"; DebugLevel[DebugLevel["info"] = 3] = "info"; DebugLevel[DebugLevel["none"] = 4] = "none"; })(DebugLevel || (DebugLevel = {})); var ElementLocation; (function (ElementLocation) { ElementLocation[ElementLocation["head"] = 0] = "head"; ElementLocation[ElementLocation["body"] = 1] = "body"; ElementLocation[ElementLocation["other"] = 2] = "other"; })(ElementLocation || (ElementLocation = {})); var appSettings = { tinyId: 'gminput', shortName: 'TMCEE', preKey: 'tmceen_', debugLevel: DebugLevel.none, menuName: 'TinyMce Options', tinyMceVersion: '4.1.0', fullScreenRealId: 'tinymce-real-fs' }; var updateAppSetting = function (key, value) { if (appSettings.hasOwnProperty(key)) { appSettings[key] = value; } }; var Log = (function () { function Log() { } Log.message = function (msg, optionalParams) { if (appSettings.debugLevel > DebugLevel.info) { return; } var params = []; if (optionalParams) { for (var i = 0; i < optionalParams.length; i++) { params[i] = optionalParams[i]; } } console.log.apply(console, [msg].concat(params)); }; Log.warn = function (msg, optionalParams) { if (appSettings.debugLevel > DebugLevel.warn) { return; } var params = []; if (optionalParams) { for (var i = 0; i < optionalParams.length; i++) { params[i] = optionalParams[i]; } } console.warn.apply(console, [msg].concat(params)); }; Log.error = function (msg, optionalParams) { if (appSettings.debugLevel > DebugLevel.error) { return; } var params = []; if (optionalParams) { for (var i = 0; i < optionalParams.length; i++) { params[i] = optionalParams[i]; } } console.error.apply(console, [msg].concat(params)); }; Log.debug = function (msg, optionalParams) { if (appSettings.debugLevel > DebugLevel.debug) { return; } var params = []; if (optionalParams) { for (var i = 0; i < optionalParams.length; i++) { params[i] = optionalParams[i]; } } console.log.apply(console, [appSettings.shortName + ": Debug: " + msg].concat(params)); }; Log.debugWarn = function (msg, optionalParams) { if (appSettings.debugLevel > DebugLevel.debug) { return; } var params = []; if (optionalParams) { for (var i = 0; i < optionalParams.length; i++) { params[i] = optionalParams[i]; } } console.warn.apply(console, [appSettings.shortName + ": Debug: " + msg].concat(params)); }; return Log; }()); var TinymceWork = (function () { function TinymceWork() { var _this = this; this.fullscreen = false; this.gmConfig = GM_config; this.init = function () { var ver = appSettings.tinyMceVersion; var id = appSettings.tinyId; tinymce.PluginManager.load('lists', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/lists/plugin.min.js'); var loadTable = _this.gmConfig.get('tinymcePluginTable'); if (loadTable) { tinymce.PluginManager.load('table', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/table/plugin.min.js'); } var loadCharmap = _this.gmConfig.get('tinymcePluginCharmap'); if (loadCharmap) { tinymce.PluginManager.load('charmap', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/charmap/plugin.min.js'); } var loadCode = _this.gmConfig.get('tinymcePluginCode'); if (loadCode) { tinymce.PluginManager.load('code', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/code/plugin.min.js'); } var loadFullscreen = _this.gmConfig.get('tinymcePluginFullscreen'); if (loadFullscreen) { tinymce.PluginManager.load('fullscreen', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/fullscreen/plugin.min.js'); } var loadEmoticons = _this.gmConfig.get('tinymcePluginEmoticons'); if (loadEmoticons) { tinymce.PluginManager.load('emoticons', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/emoticons/plugin.min.js'); } var loadWordcount = _this.gmConfig.get('tinymcePluginWordcount'); if (loadEmoticons) { tinymce.PluginManager.load('wordcount', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/wordcount/plugin.min.js'); } var loadPrint = _this.gmConfig.get('tinymcePluginPrint'); if (loadPrint) { tinymce.PluginManager.load('print', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/print/plugin.min.js'); } var loadPreview = _this.gmConfig.get('tinymcePluginPreview'); if (loadPreview) { tinymce.PluginManager.load('preview', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/preview/plugin.min.js'); } var loadInsertdatetime = _this.gmConfig.get('tinymcePluginInsertdatetime'); if (loadInsertdatetime) { tinymce.PluginManager.load('insertdatetime', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/insertdatetime/plugin.min.js'); } var loadImage = _this.gmConfig.get('tinymcePluginImage'); if (loadImage) { tinymce.PluginManager.load('image', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/image/plugin.min.js'); } var loadSearchreplace = _this.gmConfig.get('tinymcePluginSearchreplace'); if (loadSearchreplace) { tinymce.PluginManager.load('searchreplace', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/searchreplace/plugin.min.js'); } var loadAdvlist = _this.gmConfig.get('tinymcePluginAdvlist'); if (loadAdvlist) { tinymce.PluginManager.load('advlist', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/advlist/plugin.min.js'); } var loadBbcode = _this.gmConfig.get('tinymcePluginBbcode'); if (loadBbcode) { tinymce.PluginManager.load('bbcode', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/bbcode/plugin.min.js'); } var loadVisualblocks = _this.gmConfig.get('tinymcePluginVisualblocks'); if (loadVisualblocks) { tinymce.PluginManager.load('visualblocks', 'https://cdn.tinymce.com/4/plugins/visualblocks/plugin.min.js'); } var loadVisualchars = _this.gmConfig.get('tinymcePluginVisualchars'); if (loadVisualchars) { tinymce.PluginManager.load('visualchars', 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/visualchars/plugin.min.js'); } var loadHilite = _this.gmConfig.get('tinymcePluginHilite'); if (loadHilite) { tinymce.PluginManager.load('hilite', 'https://cdn.jsdelivr.net/gh/Amourspirit/TinyMCE-Plugin-hilite@9b2a96752b5162187315e07047a7c0efd706145c/js/plugin.min.js'); } var tinyMceExternalPlugins = { textcolor: 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/textcolor/plugin.min.js', colorpicker: 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/colorpicker/plugin.min.js', nonbreaking: 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/nonbreaking/plugin.min.js', hr: 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/hr/plugin.min.js', link: 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/' + ver + '/plugins/link/plugin.min.js' }; var toolbar1 = 'mysave myexit insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent'; var toolbar2 = (loadFullscreen ? 'fullscreen ' : ''); toolbar2 += (loadPrint ? 'print ' : ''); toolbar2 += (loadPreview ? 'preview ' : ''); toolbar2 += '| forecolor backcolor | '; toolbar2 += (loadPreview ? 'insertdatetime ' : ''); toolbar2 += (loadTable ? 'table ' : ''); toolbar2 += (loadSearchreplace ? 'searchreplace ' : ''); toolbar2 += '| link ' + (loadImage ? 'image ' : ''); toolbar2 += (loadEmoticons ? ' emoticons' : ''); toolbar2 += (loadCharmap ? ' | charmap' : ''); toolbar2 += (loadCode ? ' | code' : ''); toolbar2 += (loadVisualchars ? ' | visualchars' : ''); toolbar2 += (loadVisualblocks ? ' | visualblocks' : ''); toolbar2 += (loadHilite ? ' | hilite' : ''); var tinyMceInit = { selector: 'textarea#' + id, init_instance_callback: function () { $('.mce-i-mysave').addClass('save-s'); $('.mce-i-myexit').addClass('exit-x'); $(document).trigger('tinymceInit', { type: 'tinymceInit', message: 'init', time: new Date(), tinyMceId: id }); }, height: 260, inline: false, browser_spellcheck: true, plugins: '', menubar: 'edit insert format view tools' + (loadTable ? ' table' : ''), toolbar: [toolbar1, toolbar2], content_css: '', content_style: "a,blockquote,body,code,dd,del,dfn,div,dl,dt,em,h1,h2,h3,h4,h5,h6,html,iframe,img,li,ol,p,pre,q,ul{border:0;padding:0;margin:0}a,abbr,acronym,address,area,b,bdo,big,blockquote,caption,center,cite,code,col,colgroup,dd,del,dfn,div,dl,dt,em,font,h3,h4,h5,h6,hr,i,ins,kbd,li,map,ol,p,pre,q,s,samp,small,span,strike,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,tt,u,ul{line-height:1.57143em}a,body{margin:0}body,h1,h2{font-family:gotham,helvetica,arial,sans-serif}a,img[name=en-crypt]{cursor:pointer}h3,p{margin-bottom:.714285em}del{text-decoration:line-through}dfn{font-style:italic}body{box-sizing:border-box;color:#383838;font-size:14px;padding-right:1px;word-wrap:break-word}a:link,a:visited{color:#047ac6}a:active,a:hover{color:#2596de}h1{font-size:1.5em;font-weight:700;line-height:1.04762em;margin-bottom:.4761em;margin-top:.9523em}h2{font-size:1.286em;font-weight:700;line-height:1.22222em;margin-bottom:.5556em;margin-top:1.111em}h3,h4,h5,h6{font-size:1em;font-weight:700;font-family:gotham,helvetica,arial,sans-serif}h3{margin-top:1.4285em}div{font-family:gotham,helvetica,arial,sans-serif;font-size:14px}img.en-media{height:auto;margin-bottom:1.286em;max-width:100%}img.en-media[height='1']{height:1px}p+div img,p+img{margin-top:.714285em}div+div img,div+img{margin-top:.857412em}div+div img+img,img+img,li ol,li ul{margin-top:0}ol,ul{list-style-position:outside;margin-bottom:.714285em;margin-left:2em;margin-top:.2857em;padding-left:0}li ol,li ul{margin-bottom:0}h1+ol,h1+ul,h2+ol,h2+ul,p+ol,p+ul{margin-top:-.428571em}blockquote{border-left:2px solid #bfbfbf;margin-bottom:1.4285em;margin-left:1.4285em;margin-top:1.4285em;padding-left:.714285em}code,pre{font-family:Monaco,Courier,monospace}cite{font-style:italic}table{font-size:1em}td,th{padding:.2em 2em .2em 0;text-align:left;vertical-align:top}button.en-ignore{margin-bottom:1em}.highlight{background:#c9f2d0;border:1px solid #62eb92}.Decrypted{background-color:#f7f7f7;padding:5px}.Decrypted .Header{color:#404040;font-family:gotham,helvetica,arial,sans-serif;font-size:11px;padding-bottom:5px}.Decrypted .Body{background-color:#fff;padding:5px}.canvas-container{background:url(/redesign/global/img/loading-spinner.gif) center center no-repeat #fff;border:1px solid #cacaca;margin-bottom:10px}", keep_styles: false, setup: function (ed) { ed.on('FullscreenStateChanged', function (e) { _this.fullscreen = e.state; $(document).trigger('tinymceFullScreen', { type: 'tinymceFullScreen', message: 'fullscreen toogle', time: new Date(), state: e.state, tinyMceId: id }); }); ed.addButton('mysave', { title: 'Save', onclick: function () { $(document).trigger('tinymceSave', { type: 'tinymceSave', message: 'save', time: new Date(), tinyMceId: id }); } }); ed.addButton('myexit', { title: 'Close', onclick: function () { $(document).trigger('tinymceCancel', { type: 'tinymceCancel', message: 'cancel', time: new Date(), tinyMceId: id }); } }); } }; var themeOpt = _this.gmConfig.get('tinymceTheme') + ''; switch (themeOpt) { case 'Modern White': tinyMceInit.skin_url = 'https://cdn.jsdelivr.net/gh/rbecheras/tinymce-skin-modern-light-flat@dd311f2e26b2d23f15caeecca364bfcd1c40f500/light'; break; case 'Modern two': tinyMceInit.skin_url = 'https://cdn.jsdelivr.net/gh/Vodzo/tinymce_theme@b1f6cc5afd13d939cb81844b8cf2edde151de998'; break; case 'Charcoal': tinyMceInit.skin_url = 'https://cdn.jsdelivr.net/gh/Vodzo/tinymce_charcoal_theme@8d5f045120f09011d8d4c19dcebeed93932edb13'; break; case 'SS4': tinyMceInit.skin_url = 'https://cdn.jsdelivr.net/gh/DrMartinGonzo/tinymce-ss4-theme@5442568702bf1b03453e4f161d1bd5d4e79d45e0/client/dist/TinyMCE_ss4'; break; default: tinyMceInit.skin_url = ''; break; } tinyMceInit.plugins = (tinyMceInit.plugins + ' -lists').trim(); if (loadTable) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -table').trim(); } if (loadCharmap) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -charmap').trim(); } if (loadCode) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -code').trim(); tinyMceInit.code_dialog_width = parseInt(GM_config.get('tinymcePluginCodeWidth'), 10); tinyMceInit.code_dialog_height = parseInt(GM_config.get('tinymcePluginCodeHeight'), 10); } if (loadFullscreen) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -fullscreen').trim(); } if (loadEmoticons) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -emoticons').trim(); } if (loadWordcount) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -wordcount').trim(); } if (loadPrint) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -print').trim(); } if (loadPreview) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -preview').trim(); } if (loadInsertdatetime) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -insertdatetime').trim(); } if (loadImage) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -image').trim(); } if (loadSearchreplace) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -searchreplace').trim(); } if (loadAdvlist) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -advlist').trim(); } if (loadBbcode) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -bbcode').trim(); } if (loadVisualblocks) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -visualblocks').trim(); } if (loadVisualchars) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -visualchars').trim(); } if (loadHilite) { tinyMceInit.plugins = (tinyMceInit.plugins + ' -hilite').trim(); } tinyMceInit.external_plugins = tinyMceExternalPlugins; tinymce.init(tinyMceInit); }; } return TinymceWork; }()); var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var management = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var EventManagement = (function () { function EventManagement(unsub) { this.unsub = unsub; this.propagationStopped = false; } EventManagement.prototype.stopPropagation = function () { this.propagationStopped = true; }; return EventManagement; }()); exports.EventManagement = EventManagement; }); unwrapExports(management); var management_1 = management.EventManagement; var subscription = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var Subscription = (function () { function Subscription(handler, isOnce) { this.handler = handler; this.isOnce = isOnce; this.isExecuted = false; } Subscription.prototype.execute = function (executeAsync, scope, args) { if (!this.isOnce || !this.isExecuted) { this.isExecuted = true; var fn = this.handler; if (executeAsync) { setTimeout(function () { fn.apply(scope, args); }, 1); } else { fn.apply(scope, args); } } }; return Subscription; }()); exports.Subscription = Subscription; }); unwrapExports(subscription); var subscription_1 = subscription.Subscription; var dispatching = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var DispatcherBase = (function () { function DispatcherBase() { this._wrap = new DispatcherWrapper(this); this._subscriptions = new Array(); } DispatcherBase.prototype.subscribe = function (fn) { var _this = this; if (fn) { this._subscriptions.push(new subscription.Subscription(fn, false)); } return function () { _this.unsubscribe(fn); }; }; DispatcherBase.prototype.sub = function (fn) { return this.subscribe(fn); }; DispatcherBase.prototype.one = function (fn) { var _this = this; if (fn) { this._subscriptions.push(new subscription.Subscription(fn, true)); } return function () { _this.unsubscribe(fn); }; }; DispatcherBase.prototype.has = function (fn) { if (!fn) return false; return this._subscriptions.some(function (sub) { return sub.handler == fn; }); }; DispatcherBase.prototype.unsubscribe = function (fn) { if (!fn) return; for (var i = 0; i < this._subscriptions.length; i++) { if (this._subscriptions[i].handler == fn) { this._subscriptions.splice(i, 1); break; } } }; DispatcherBase.prototype.unsub = function (fn) { this.unsubscribe(fn); }; DispatcherBase.prototype._dispatch = function (executeAsync, scope, args) { var _this = this; var _loop_1 = function (sub) { var ev = new management.EventManagement(function () { return _this.unsub(sub.handler); }); var nargs = Array.prototype.slice.call(args); nargs.push(ev); sub.execute(executeAsync, scope, nargs); this_1.cleanup(sub); if (!executeAsync && ev.propagationStopped) { return "break"; } }; var this_1 = this; for (var _i = 0, _a = this._subscriptions.slice(); _i < _a.length; _i++) { var sub = _a[_i]; var state_1 = _loop_1(sub); if (state_1 === "break") break; } }; DispatcherBase.prototype.cleanup = function (sub) { if (sub.isOnce && sub.isExecuted) { var i = this._subscriptions.indexOf(sub); if (i > -1) { this._subscriptions.splice(i, 1); } } }; DispatcherBase.prototype.asEvent = function () { return this._wrap; }; DispatcherBase.prototype.clear = function () { this._subscriptions.splice(0, this._subscriptions.length); }; return DispatcherBase; }()); exports.DispatcherBase = DispatcherBase; var EventListBase = (function () { function EventListBase() { this._events = {}; } EventListBase.prototype.get = function (name) { var event = this._events[name]; if (event) { return event; } event = this.createDispatcher(); this._events[name] = event; return event; }; EventListBase.prototype.remove = function (name) { delete this._events[name]; }; return EventListBase; }()); exports.EventListBase = EventListBase; var DispatcherWrapper = (function () { function DispatcherWrapper(dispatcher) { this._subscribe = function (fn) { return dispatcher.subscribe(fn); }; this._unsubscribe = function (fn) { return dispatcher.unsubscribe(fn); }; this._one = function (fn) { return dispatcher.one(fn); }; this._has = function (fn) { return dispatcher.has(fn); }; this._clear = function () { return dispatcher.clear(); }; } DispatcherWrapper.prototype.subscribe = function (fn) { return this._subscribe(fn); }; DispatcherWrapper.prototype.sub = function (fn) { return this.subscribe(fn); }; DispatcherWrapper.prototype.unsubscribe = function (fn) { this._unsubscribe(fn); }; DispatcherWrapper.prototype.unsub = function (fn) { this.unsubscribe(fn); }; DispatcherWrapper.prototype.one = function (fn) { return this._one(fn); }; DispatcherWrapper.prototype.has = function (fn) { return this._has(fn); }; DispatcherWrapper.prototype.clear = function () { this._clear(); }; return DispatcherWrapper; }()); exports.DispatcherWrapper = DispatcherWrapper; }); unwrapExports(dispatching); var dispatching_1 = dispatching.DispatcherBase; var dispatching_2 = dispatching.EventListBase; var dispatching_3 = dispatching.DispatcherWrapper; var dist = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.DispatcherBase = dispatching.DispatcherBase; exports.DispatcherWrapper = dispatching.DispatcherWrapper; exports.EventListBase = dispatching.EventListBase; exports.Subscription = subscription.Subscription; }); unwrapExports(dist); var dist_1 = dist.DispatcherBase; var dist_2 = dist.DispatcherWrapper; var dist_3 = dist.EventListBase; var dist_4 = dist.Subscription; var events = createCommonjsModule(function (module, exports) { var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var EventDispatcher = (function (_super) { __extends(EventDispatcher, _super); function EventDispatcher() { return _super.call(this) || this; } EventDispatcher.prototype.dispatch = function (sender, args) { this._dispatch(false, this, arguments); }; EventDispatcher.prototype.dispatchAsync = function (sender, args) { this._dispatch(true, this, arguments); }; EventDispatcher.prototype.asEvent = function () { return _super.prototype.asEvent.call(this); }; return EventDispatcher; }(dist.DispatcherBase)); exports.EventDispatcher = EventDispatcher; var EventList = (function (_super) { __extends(EventList, _super); function EventList() { return _super.call(this) || this; } EventList.prototype.createDispatcher = function () { return new EventDispatcher(); }; return EventList; }(dist.EventListBase)); exports.EventList = EventList; var EventHandlingBase = (function () { function EventHandlingBase() { this._events = new EventList(); } Object.defineProperty(EventHandlingBase.prototype, "events", { get: function () { return this._events; }, enumerable: true, configurable: true }); EventHandlingBase.prototype.subscribe = function (name, fn) { this._events.get(name).subscribe(fn); }; EventHandlingBase.prototype.sub = function (name, fn) { this.subscribe(name, fn); }; EventHandlingBase.prototype.unsubscribe = function (name, fn) { this._events.get(name).unsubscribe(fn); }; EventHandlingBase.prototype.unsub = function (name, fn) { this.unsubscribe(name, fn); }; EventHandlingBase.prototype.one = function (name, fn) { this._events.get(name).one(fn); }; EventHandlingBase.prototype.has = function (name, fn) { return this._events.get(name).has(fn); }; return EventHandlingBase; }()); exports.EventHandlingBase = EventHandlingBase; }); unwrapExports(events); var events_1 = events.EventDispatcher; var events_2 = events.EventList; var events_3 = events.EventHandlingBase; var dist$1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.EventDispatcher = events.EventDispatcher; exports.EventHandlingBase = events.EventHandlingBase; exports.EventList = events.EventList; }); unwrapExports(dist$1); var dist_1$1 = dist$1.EventDispatcher; var dist_2$1 = dist$1.EventHandlingBase; var dist_3$1 = dist$1.EventList; var simpleEvents = createCommonjsModule(function (module, exports) { var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var SimpleEventDispatcher = (function (_super) { __extends(SimpleEventDispatcher, _super); function SimpleEventDispatcher() { return _super.call(this) || this; } SimpleEventDispatcher.prototype.dispatch = function (args) { this._dispatch(false, this, arguments); }; SimpleEventDispatcher.prototype.dispatchAsync = function (args) { this._dispatch(true, this, arguments); }; SimpleEventDispatcher.prototype.asEvent = function () { return _super.prototype.asEvent.call(this); }; return SimpleEventDispatcher; }(dist.DispatcherBase)); exports.SimpleEventDispatcher = SimpleEventDispatcher; var SimpleEventList = (function (_super) { __extends(SimpleEventList, _super); function SimpleEventList() { return _super.call(this) || this; } SimpleEventList.prototype.createDispatcher = function () { return new SimpleEventDispatcher(); }; return SimpleEventList; }(dist.EventListBase)); exports.SimpleEventList = SimpleEventList; var SimpleEventHandlingBase = (function () { function SimpleEventHandlingBase() { this._events = new SimpleEventList(); } Object.defineProperty(SimpleEventHandlingBase.prototype, "events", { get: function () { return this._events; }, enumerable: true, configurable: true }); SimpleEventHandlingBase.prototype.subscribe = function (name, fn) { this._events.get(name).subscribe(fn); }; SimpleEventHandlingBase.prototype.sub = function (name, fn) { this.subscribe(name, fn); }; SimpleEventHandlingBase.prototype.one = function (name, fn) { this._events.get(name).one(fn); }; SimpleEventHandlingBase.prototype.has = function (name, fn) { return this._events.get(name).has(fn); }; SimpleEventHandlingBase.prototype.unsubscribe = function (name, fn) { this._events.get(name).unsubscribe(fn); }; SimpleEventHandlingBase.prototype.unsub = function (name, fn) { this.unsubscribe(name, fn); }; return SimpleEventHandlingBase; }()); exports.SimpleEventHandlingBase = SimpleEventHandlingBase; }); unwrapExports(simpleEvents); var simpleEvents_1 = simpleEvents.SimpleEventDispatcher; var simpleEvents_2 = simpleEvents.SimpleEventList; var simpleEvents_3 = simpleEvents.SimpleEventHandlingBase; var dist$2 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleEventDispatcher = simpleEvents.SimpleEventDispatcher; exports.SimpleEventHandlingBase = simpleEvents.SimpleEventHandlingBase; exports.SimpleEventList = simpleEvents.SimpleEventList; }); unwrapExports(dist$2); var dist_1$2 = dist$2.SimpleEventDispatcher; var dist_2$2 = dist$2.SimpleEventHandlingBase; var dist_3$2 = dist$2.SimpleEventList; var signals = createCommonjsModule(function (module, exports) { var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var SignalDispatcher = (function (_super) { __extends(SignalDispatcher, _super); function SignalDispatcher() { return _super.call(this) || this; } SignalDispatcher.prototype.dispatch = function () { this._dispatch(false, this, arguments); }; SignalDispatcher.prototype.dispatchAsync = function () { this._dispatch(true, this, arguments); }; SignalDispatcher.prototype.asEvent = function () { return _super.prototype.asEvent.call(this); }; return SignalDispatcher; }(dist.DispatcherBase)); exports.SignalDispatcher = SignalDispatcher; var SignalList = (function (_super) { __extends(SignalList, _super); function SignalList() { return _super.call(this) || this; } SignalList.prototype.createDispatcher = function () { return new SignalDispatcher(); }; return SignalList; }(dist.EventListBase)); exports.SignalList = SignalList; var SignalHandlingBase = (function () { function SignalHandlingBase() { this._events = new SignalList(); } Object.defineProperty(SignalHandlingBase.prototype, "events", { get: function () { return this._events; }, enumerable: true, configurable: true }); SignalHandlingBase.prototype.one = function (name, fn) { this._events.get(name).one(fn); }; SignalHandlingBase.prototype.has = function (name, fn) { return this._events.get(name).has(fn); }; SignalHandlingBase.prototype.subscribe = function (name, fn) { this._events.get(name).subscribe(fn); }; SignalHandlingBase.prototype.sub = function (name, fn) { this.subscribe(name, fn); }; SignalHandlingBase.prototype.unsubscribe = function (name, fn) { this._events.get(name).unsubscribe(fn); }; SignalHandlingBase.prototype.unsub = function (name, fn) { this.unsubscribe(name, fn); }; return SignalHandlingBase; }()); exports.SignalHandlingBase = SignalHandlingBase; }); unwrapExports(signals); var signals_1 = signals.SignalDispatcher; var signals_2 = signals.SignalList; var signals_3 = signals.SignalHandlingBase; var dist$3 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.SignalDispatcher = signals.SignalDispatcher; exports.SignalHandlingBase = signals.SignalHandlingBase; exports.SignalList = signals.SignalList; }); unwrapExports(dist$3); var dist_1$3 = dist$3.SignalDispatcher; var dist_2$3 = dist$3.SignalHandlingBase; var dist_3$3 = dist$3.SignalList; var dist$4 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.DispatcherBase = dist.DispatcherBase; exports.DispatcherWrapper = dist.DispatcherWrapper; exports.EventListBase = dist.EventListBase; exports.Subscription = dist.Subscription; exports.EventDispatcher = dist$1.EventDispatcher; exports.EventHandlingBase = dist$1.EventHandlingBase; exports.EventList = dist$1.EventList; exports.SimpleEventDispatcher = dist$2.SimpleEventDispatcher; exports.SimpleEventHandlingBase = dist$2.SimpleEventHandlingBase; exports.SimpleEventList = dist$2.SimpleEventList; exports.SignalDispatcher = dist$3.SignalDispatcher; exports.SignalHandlingBase = dist$3.SignalHandlingBase; exports.SignalList = dist$3.SignalList; }); unwrapExports(dist$4); var dist_1$4 = dist$4.DispatcherBase; var dist_2$4 = dist$4.DispatcherWrapper; var dist_3$4 = dist$4.EventListBase; var dist_4$1 = dist$4.Subscription; var dist_5 = dist$4.EventDispatcher; var dist_6 = dist$4.EventHandlingBase; var dist_7 = dist$4.EventList; var dist_8 = dist$4.SimpleEventDispatcher; var dist_9 = dist$4.SimpleEventHandlingBase; var dist_10 = dist$4.SimpleEventList; var dist_11 = dist$4.SignalDispatcher; var dist_12 = dist$4.SignalHandlingBase; var dist_13 = dist$4.SignalList; var EventArgs = (function () { function EventArgs() { this.cancel = false; } return EventArgs; }()); var IntervalEventArgs = (function (_super) { __extends(IntervalEventArgs, _super); function IntervalEventArgs(ticks, interval) { if (interval === void 0) { interval = 0; } var _this = _super.call(this) || this; _this.lCount = ticks; _this.lInterval = interval; return _this; } Object.defineProperty(IntervalEventArgs.prototype, "count", { get: function () { return this.lCount; }, enumerable: true, configurable: true }); Object.defineProperty(IntervalEventArgs.prototype, "interval", { get: function () { return this.lInterval; }, enumerable: true, configurable: true }); return IntervalEventArgs; }(EventArgs)); var exceptionMessages = { argLessThenZero: 'Argument "{0}" must to be zero or greater', argLessThenOne: 'Argument "{0}" must be one or greater', argEmptyString: 'Argument "{0}" is not allowed to be an empty string', argKeyExist: 'Argument "{0}" invalid key. Key "{1}" already exist.' }; Number.prototype.thousandsSeperator = function () { return Number(this).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); }; String.Format = function (str) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } return str.replace(/{(\d+)}/g, function (match, index) { return args[index] || ''; }); }; var Interval = (function () { function Interval(interval, maxCount) { var _this = this; this.edOnTick = new dist_5(); this.edOnTickExpired = new dist_5(); this.lTick = 0; this.lIsDisposed = false; this.isAtInterval = function () { return _this.lTick > _this.lMaxTick; }; this.lMaxTick = maxCount; this.lIntervalTime = interval; if (this.lIntervalTime < 0) { throw new RangeError(String.Format(exceptionMessages.argLessThenZero, 'interval')); } if (this.lMaxTick < 1) { return; } this.startInterval(); } Interval.prototype.onTick = function () { return this.edOnTick.asEvent(); }; Interval.prototype.onExpired = function () { return this.edOnTickExpired.asEvent(); }; Interval.prototype.dispose = function () { if (this.lIsDisposed === true) { return; } try { if (this.lInterval) { clearInterval(this.lInterval); } } finally { this.lMaxTick = 0; this.lIntervalTime = 0; this.lMaxTick = 0; this.lIsDisposed = true; } }; Object.defineProperty(Interval.prototype, "isDisposed", { get: function () { return this.lIsDisposed; }, enumerable: true, configurable: true }); Object.defineProperty(Interval.prototype, "count", { get: function () { return this.lTick; }, enumerable: true, configurable: true }); Interval.prototype.startInterval = function () { var _this = this; this.lInterval = setInterval(function () { _this.tick(); }, this.lIntervalTime); }; Interval.prototype.onTickTock = function (eventArgs) { if (eventArgs.cancel === true) { return; } return; }; Interval.prototype.onTicks = function (eventArgs) { if (eventArgs.cancel === true) { return; } return; }; Interval.prototype.onTickExpired = function (eventArgs) { if (eventArgs.cancel === true) { return; } return; }; Interval.prototype.tick = function () { this.lTick += 1; var eventArgs = new IntervalEventArgs(this.lTick, this.lIntervalTime); this.onTicks(eventArgs); if (this.isAtInterval()) { if (this.lInterval) { clearInterval(this.lInterval); } this.onTickExpired(eventArgs); if (eventArgs.cancel === true) { return; } this.edOnTickExpired.dispatch(this, eventArgs); } else { this.onTickTock(eventArgs); if (eventArgs.cancel === true) { return; } this.edOnTick.dispatch(this, eventArgs); } }; return Interval; }()); var IntervalManual = (function (_super) { __extends(IntervalManual, _super); function IntervalManual(interval, maxCount) { var _this = _super.call(this, interval, maxCount) || this; _this.lIsStarted = false; return _this; } IntervalManual.prototype.start = function () { if (this.isStarted === true) { return; } this.lIsStarted = true; _super.prototype.startInterval.call(this); }; IntervalManual.prototype.dispose = function () { this.lIsStarted = false; _super.prototype.dispose.call(this); }; Object.defineProperty(IntervalManual.prototype, "isStarted", { get: function () { return this.lIsStarted; }, enumerable: true, configurable: true }); IntervalManual.prototype.startInterval = function () { }; return IntervalManual; }(Interval)); var Evernote = (function () { function Evernote() { var _this = this; this.btnSelector = ''; this.iframeSelector = ''; this.noteSelector = ''; this.tinymceDivId = ''; this.fullScreen = false; this.TMCE = new TinymceWork(); this.init = function () { _this.allScriptsLoaded(); }; this.onTinymceInit = function (e) { Log.message(appSettings.shortName + ': Tiny Mce Init was triggered'); }; this.onTinymceSave = function (e, data) { if (data.tinyMceId === appSettings.tinyId) { _this.save(); _this.lightBoxReset(); var ed = tinymce__default.EditorManager.editors[data.tinyMceId]; if (!ed) { Log.error(methodName + ": Editor was not found and is null. Param e, data", [e, data]); } ed.setContent(''); } }; this.onTinymceCancel = function (e, data) { if (data.tinyMceId === appSettings.tinyId) { var ed = tinymce__default.EditorManager.editors[data.tinyMceId]; if (!ed) { Log.error(methodName + ": Editor was not found and is null. Params e, data", [e, data]); } var confirm_1 = GM_config.get('tinymceConfirmNoSaveExit'); if (confirm_1) { if (_this.confirmExit()) { _this.lightBoxReset(); ed.setContent(''); } } else { _this.lightBoxReset(); ed.setContent(''); } } }; this.onTinyMceFulllscreen = function (e, data) { if (data.tinyMceId === appSettings.tinyId) { _this.getTinymceDivId(); _this.fullScreen = e.state; if (data.state) { if ($('#tinybox').hasClass('gmbox-window')) { $('#tinybox').removeClass('gmbox-window'); } } else { if (!$('#tinybox').hasClass('gmbox-window')) { $('#tinybox').addClass('gmbox-window'); } } } }; this.confirmExit = function () { return confirm('Are you sure you want to close this editor?'); }; this.save = function () { var k = appSettings.tinyId; var ed = tinymce__default.EditorManager.editors[k]; var e = ed.getContent(); $('.gmbackdrop, .gmbox').animate({ opacity: '0' }, 300, 'linear', function () { $('.gmbackdrop, .gmbox').css('display', 'none'); }); var content = $(_this.iframeSelector).contents().find(_this.noteSelector); content.html(e); $('textarea#gminput').val(''), ed.setContent(''); }; } Evernote.prototype.allScriptsLoaded = function () { Log.message(appSettings.shortName + ': all scripts have been loaded.'); this.btnSelector = '//*[@id="gwt-debug-NoteAttributesView-root"]/div[1]/div[1]'; if (/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())) { this.iframeSelector = '.RichTextArea-entinymce'; this.noteSelector = 'body'; } else { this.iframeSelector = '.RichTextArea-entinymce'; this.noteSelector = 'body'; } this.ensurePlugins(); this.addToolbarButton(); $(document).on('editBtnAdded', this.onEditBtnAdded); $(document).on('tinymceInit', this.onTinymceInit); $(document).on('tinymceSave', this.onTinymceSave); $(document).on('tinymceCancel', this.onTinymceCancel); $(document).on('tinymceFullScreen', this.onTinyMceFulllscreen); this.TMCE.init(); var intGmboxPadLeft = parseInt($('.gmbox').css('padding-left'), 10); var intGmboxPadRight = parseInt($('.gmbox').css('padding-right'), 10); var intTinymceWidth = parseInt(GM_config.get('tinymceWidth'), 10); intTinymceWidth = intTinymceWidth - (intGmboxPadLeft + intGmboxPadRight); $('.gmbox-window').width(intTinymceWidth); $('.gmclose').click(function () { $(document).trigger('tinymceCancel', { message: 'cancel', tinyMceId: appSettings.tinyId }); }); }; Evernote.prototype.onEditBtnAdded = function () { Log.message(appSettings.shortName + ': onEditBtnAdded event fired'); this.addButtonClick(); }; Evernote.prototype.addButtonClick = function () { var _this = this; if ($('#gm-edit-btn').length) { $('#gm-edit-btn').click(function () { var k = appSettings.tinyId; var ed = tinymce__default.EditorManager.editors[k]; if (_this.fullScreen) { ed.execCommand('mceFullScreen'); } ed.setContent($(_this.iframeSelector).contents().find(_this.noteSelector).html()); $('.gmbackdrop, .gmbox').animate({ opacity: '.50' }, 300, 'linear'); $('.gmbox').animate({ opacity: '1.00' }, 300, 'linear'); $('.gmbackdrop, .gmbox').css('display', 'block'); }); Log.message(appSettings.shortName + ": Edit Button Click added"); } else { Log.error(appSettings.shortName + ": addButtonClick: #gm-edit-btn was not found"); } }; Evernote.prototype.addToolbarButton = function () { var _this = this; var ivm = new IntervalManual(500, 20); var tickCount = 0; ivm.onTick().subscribe(function (sender, args) { tickCount++; Log.message(appSettings.shortName + ": try no. " + tickCount + " to find element for button pacement"); var objElement = $(document.body).xpath(_this.btnSelector); if (objElement.length) { ivm.dispose(); Log.message(appSettings.shortName + ": Found element for button placement on " + tickCount + " try"); objElement.append(_this.createToolbarHtml()); _this.onEditBtnAdded(); } }); ivm.onExpired().subscribe(function (sender, args) { Log.error(methodName + ": unable to located selector for main button after " + args.count + " attempts"); }); ivm.start(); }; Evernote.prototype.createToolbarHtml = function () { var css = ''; var btnHtml = "
"; var html = ''; html += "