diff --git a/customiser.py b/customiser.py index 8eb3bc5..ac69400 100755 --- a/customiser.py +++ b/customiser.py @@ -126,7 +126,8 @@ try: f' ...linking to {os.path.join(".", "resources", "user.css")}') with open(os.path.join(__dirname__, 'resources', 'preload.js'), 'r', encoding='UTF-8') as insert: append.write(insert.read().replace( - '☃☃☃resources☃☃☃', os.path.join(enhancer_folder, 'resources').replace('\\', '/'))) + '☃☃☃resources☃☃☃', os.path.join(enhancer_folder, 'resources').replace('\\', '/')) + .replace('☃☃☃version☃☃☃', enhancer_version)) else: print( f' * {os.path.join(filepath, "app","renderer","preload.js")} was not found: step skipped.') diff --git a/resources/preload.js b/resources/preload.js index 7d92897..5e9e12b 100644 --- a/resources/preload.js +++ b/resources/preload.js @@ -167,9 +167,40 @@ require('electron').remote.getGlobal('setTimeout')(() => { el.outerHTML = `${el.getAttribute('alt')}`; }); }); - observer.observe(document, { childList: true, subtree: true }); + observer.observe(document, { + childList: true, + subtree: true, + }); } + /* update checker */ + fetch( + `https://api.github.com/repos/dragonwocky/notion-enhancer/releases/latest` + ) + .then((res) => res.json()) + .then((res) => { + const local_version = '☃☃☃version☃☃☃'.split('~')[0], + repo_version = res.tag_name.slice(1); + // compare func from https://github.com/substack/semver-compare + if ( + local_version != repo_version && + [local_version, repo_version].sort((a, b) => { + var pa = a.split('.'); + var pb = b.split('.'); + for (var i = 0; i < 3; i++) { + var na = Number(pa[i]); + var nb = Number(pb[i]); + if (na > nb) return 1; + if (nb > na) return -1; + if (!isNaN(na) && isNaN(nb)) return 1; + if (isNaN(na) && !isNaN(nb)) return -1; + } + return 0; + })[0] == local_version + ) + alert('notion-enhancer update available!'); + }); + /* hotkey: reload window */ document.defaultView.addEventListener( 'keyup',