From e18320acb30966527d7ed81a2fabbbca89ad3f59 Mon Sep 17 00:00:00 2001 From: Send_Nukez Date: Sun, 28 Nov 2021 01:47:32 +0100 Subject: [PATCH] prevent js from being executed multiple times --- src/js/main.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 955f201..4120c5e 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -4,13 +4,15 @@ import chroma from "chroma-js"; import $ from "jquery"; import moment from "moment"; +// Break if Dribbblish has already been initialized +if ($("html").attr("dribbblish-js-installed") != undefined) throw new Error("Dribbblish has already been initialized"); +// Remove not installed message +$("html").attr("dribbblish-js-installed", " "); + import { waitForElement, copyToClipboard, capitalizeFirstLetter, getClosestToNum, randomFromArray, debounce } from "./Util"; import { default as _Dribbblish } from "./Dribbblish"; import "./Folders"; -// Remove not installed message -$("html").attr("dribbblish-js-installed", " "); - // To expose to external scripts const Dribbblish = new _Dribbblish(); window.Dribbblish = Dribbblish; @@ -64,7 +66,6 @@ Dribbblish.on("ready", () => { defaultValue: true, onChange: (val) => $("#main").attr("search-box", val ? "" : null), onAppended: () => { - if ($("#dribbblish-search-box").length != 0) return; const input = document.createElement("input"); input.id = "dribbblish-search-box"; input.type = "search";