diff --git a/src/public/plugins/index.js b/src/public/plugins/index.js index 5c084b01..b74b7bac 100644 --- a/src/public/plugins/index.js +++ b/src/public/plugins/index.js @@ -252,13 +252,16 @@ export var Plugins = function (app) { const isGistTokenInvalid = () => { return app.data.storage.getIsTokenInvalid(); } - const urlParams = new URLSearchParams(window.location.href.split('?')[1]); - const gistPluginsId = urlParams.get('gistPlugins'); - const gistPluginsFileUrl = urlParams.get('pluginFile'); + // const urlParams = new URLSearchParams(window.location.href.split('?')[1]); + const url = new URL(window.location.href); + const urlParams = url.searchParams; + console.log({urlParams, url}) + const getGistPluginsId = () => urlParams.get('gistPlugins') || app.settings.gistPluginsFile(); + const getGistPluginsFileUrl = () => urlParams.get('pluginFile'); const pluginModeUrl = urlParams.get('mode'); const updateUrlParams = (key, value) => { - const url = new URL(window.location.href); + console.log("updateUrlParams", {key, value}) if (value) { url.searchParams.set(key, value); } else { @@ -269,9 +272,8 @@ export var Plugins = function (app) { this.rawUrls = {}; const getGistPluginFiles = () => { return new Promise((resolve) => { - const gistId = gistPluginsId || app.settings.gistPluginsFile(); app.data.storage - .getGist(gistId) + .getGist(getGistPluginsId()) .then(({ filesInGist }) => { const promises = Object.values(filesInGist) .filter(gistFile => gistFile.language === 'JavaScript' || gistFile.filename.endsWith(".js")) @@ -287,7 +289,6 @@ export var Plugins = function (app) { }; const getGistPluginFile = (fileName) => { - const gistId = gistPluginsId || app.settings.gistPluginsFile(); const rawUrl = this.rawUrls[fileName] if (!rawUrl) return Promise.resolve(''); return app.data.storage.getGistFileFromRawUrl(rawUrl); @@ -322,7 +323,7 @@ export var Plugins = function (app) { } const deleteGistPlugin = (fileName) => { - return app.data.storage.deleteGistFile(gistPluginsId || app.settings.gistPluginsFile(), fileName); + return app.data.storage.deleteGistFile(getGistPluginsId(), fileName); } const getExtensionScriptData = (fileContents) => { @@ -523,7 +524,8 @@ export var Plugins = function (app) { isGistTokenInvalid, urlParams, updateUrlParams, - gistPluginsFileUrl, + getGistPluginsFileUrl, + getGistPluginsId, pluginModeUrl, getPluginsList, deleteGistPlugin, diff --git a/src/public/plugins/plugin-editor.js b/src/public/plugins/plugin-editor.js index 00b93e35..e66ef759 100644 --- a/src/public/plugins/plugin-editor.js +++ b/src/public/plugins/plugin-editor.js @@ -146,9 +146,10 @@ export var PluginEditor = function ({ getGistPluginFile, saveGistPlugin, isGistTokenInvalid, - gistPluginsFileUrl, - pluginModeUrl, + getGistPluginsFileUrl, urlParams, + pluginModeUrl, + getGistPluginsId, updateUrlParams, getPluginsList, deleteGistPlugin, @@ -226,7 +227,14 @@ export var PluginEditor = function ({ this.onDownloadPreview = () => { app.data.storage.downloadContent(document.getElementById('plugin-output-previewer').srcdoc, 'output.html'); } - this.onSetPluginEditMode = mode => { + this.onCopyLink = () => { + window.navigator.clipboard.writeText(window.location.href); + ToastWc.show({ type: 'success', content: `Copied ${window.location.href} to clipboard!`, time: 3000 }) + } + this.onOpenGistLink = () => { + window.open(`https://gist.github.com/${getGistPluginsId()}`, "_blank"); + } + this.onSetPluginEditMode = (mode) => { this.mode = mode; setPluginStore(self.name, 'pluginEditMode', mode); document @@ -245,6 +253,8 @@ export var PluginEditor = function ({ mode === 'commit' ? 'block' : 'none'; document.getElementById('plugin-differ-commit').style.display = mode === 'commit' ? 'block' : 'none'; + document.getElementById('plugin-differ-link').style.display = + mode === 'commit' ? 'block' : 'none'; document.getElementById('plugin-output-previewer').style.height = mode === 'test' ? HEIGHT : '0vh'; document.getElementById('plugin-output-previewer').style.position = mode === 'test' ? 'relative' : 'absolute'; @@ -252,6 +262,7 @@ export var PluginEditor = function ({ document.getElementById('plugin-output-previewer').sandbox = mode === 'test' ? `allow-scripts allow-modals allow-same-origin`: `allow-scripts allow-same-origin`; document.getElementById('plugin-output-downloader').style.display = mode === 'test' ? 'block' : 'none'; + document.getElementById('plugin-output-linker').style.display = mode === 'test' ? 'block' : 'none'; updateUrlParams('mode', mode); this.onSetEditingFile(); @@ -314,6 +325,7 @@ export var PluginEditor = function ({ let fileContents = this.volatilePlugins[this.editingFile].content; this.editor.setValue(fileContents); this.editor.clearSelection(); + console.log("update plugins file::" , this.editingFile) updateUrlParams('pluginFile', this.editingFile); if (this.mode === 'commit') { @@ -421,8 +433,20 @@ export var PluginEditor = function ({ > Save to Gist + - +
format
+
+ +
+