From ba7073cb5fb6fcf1e6e532f660bca985756e3770 Mon Sep 17 00:00:00 2001 From: saif malik Date: Mon, 11 Oct 2021 18:35:28 +0530 Subject: [PATCH] Open div according to the number of links --- src/content.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content.js b/src/content.js index e738059..b189469 100644 --- a/src/content.js +++ b/src/content.js @@ -1,14 +1,14 @@ browser.runtime.onMessage.addListener(() => { - toggleSidebar(); + toggleSidebar(linksArray.length); return Promise.resolve({ response: 'Msg from content script.' }); }); -const toggleSidebar = () => { +const toggleSidebar = (length) => { const hnmain = document.getElementById('hnmain'); const linksDiv = document.getElementsByClassName('linksDiv')[0]; - if (hnmain.align === 'left') { + if (length === undefined || length === 0 || hnmain.align === 'left') { linksDiv.style.display = 'none'; hnmain.width = '85%'; hnmain.align = 'center'; @@ -215,7 +215,7 @@ function createLinksArrayElement (linksArray) { const linksArray = createLinksArray(); createLinksArrayElement(linksArray); -toggleSidebar(); +toggleSidebar(linksArray.length); // Ellipsify the comment texts to three lines