From 1283e85a8ea69be788621f830867a398998947a5 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 14 Dec 2017 01:46:32 +0300 Subject: [PATCH] update USO style install counter the USO site reports style installation unconditionally even if you uninstall it in 5 seconds, but we do it only if the style isn't uninstalled during 60 seconds while the popup is open - thus we exclude previewing of styles, which is a very popular use case --- popup/search-results.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/popup/search-results.js b/popup/search-results.js index 320d86c4..c3234f6f 100755 --- a/popup/search-results.js +++ b/popup/search-results.js @@ -36,6 +36,10 @@ window.addEventListener('showStyles:done', function _() { // Millisecs to wait before fetching .JSON for next search result. const DELAY_BEFORE_SEARCHING_STYLES = 0; + // update USO style install counter + // if the style isn't uninstalled in the popup + const PINGBACK_DELAY = 60e3; + const BLANK_PIXEL_DATA = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAA' + 'C1HAwCAAAAC0lEQVR42mOcXQ8AAbsBHLLDr5MAAAAASUVORK5CYII='; @@ -131,6 +135,7 @@ window.addEventListener('showStyles:done', function _() { if (result) { result.installed = false; result.installedStyleId = -1; + BG.clearTimeout(result.pingbackTimer); renderActionButtons($('#' + RESULT_ID_PREFIX + result.id)); } }); @@ -558,6 +563,7 @@ window.addEventListener('showStyles:done', function _() { fetchStyleSettings(result), ]) .then(([style, settings]) => { + pingback(result); // show a 'config-on-homepage' icon in the popup style.updateUrl += settings.length ? '?' : ''; // show a 'style installed' tooltip in the manager @@ -585,6 +591,11 @@ window.addEventListener('showStyles:done', function _() { } } + function pingback(result) { + result.pingbackTimer = BG.setTimeout(BG.download, PINGBACK_DELAY, + BASE_URL + '/styles/install/' + result.id + '?source=stylish-ch'); + } + function saveScrollPosition(entry) { dom.scrollPosition = entry.getBoundingClientRect().top; dom.scrollPositionElement = entry;