From 9ab996a5f01ef88d72d8d5bb28fea518db8c88e6 Mon Sep 17 00:00:00 2001 From: Bennett Date: Sun, 12 Apr 2020 13:33:11 +0200 Subject: Improve user scripts (#559) * Add template to user.js creation * Add Userscript library * Add internalOpen function * Fix lint * Remove excess line break --- src/webview/recipe.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/webview/recipe.js') diff --git a/src/webview/recipe.js b/src/webview/recipe.js index bad5a93b2..7b762af17 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js @@ -21,6 +21,7 @@ import ignoreList from './darkmode/ignore'; import customDarkModeCss from './darkmode/custom'; import RecipeWebview from './lib/RecipeWebview'; +import Userscript from './lib/Userscript'; import spellchecker, { switchDict, disable as disableSpellchecker, getSpellcheckerLocaleByFuzzyIdentifier } from './spellchecker'; import { injectDarkModeStyle, isDarkModeStyleInjected, removeDarkModeStyle } from './darkmode'; @@ -55,6 +56,8 @@ class RecipeController { recipe = null; + userscript = null; + hasUpdatedBeforeRecipeLoaded = false; constructor() { @@ -130,7 +133,8 @@ class RecipeController { const userJsModule = require(userJs); if (typeof userJsModule === 'function') { - userJsModule(config); + this.userscript = new Userscript(this.recipe, this, config); + userJsModule(config, this.userscript); } }; @@ -154,6 +158,10 @@ class RecipeController { debug('System spellcheckerLanguage', this.settings.app.spellcheckerLanguage); debug('Service spellcheckerLanguage', this.settings.service.spellcheckerLanguage); + if (this.userscript && this.userscript.internal_setSettings) { + this.userscript.internal_setSettings(this.settings); + } + if (this.settings.app.enableSpellchecking) { debug('Setting spellchecker language to', this.spellcheckerLanguage); let { spellcheckerLanguage } = this; @@ -322,7 +330,6 @@ new RecipeController(); // Patching window.open const originalWindowOpen = window.open; - window.open = (url, frameName, features) => { if (!url && !frameName && !features) { // The service hasn't yet supplied a URL (as used in Skype). -- cgit v1.2.3-54-g00ecf