Skip to content

Commit

Permalink
Change the banner when multiple articles are found on the page #37
Browse files Browse the repository at this point in the history
  • Loading branch information
rmfsdev committed Dec 14, 2021
1 parent e4fa545 commit f9b5758
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
64 changes: 56 additions & 8 deletions js/contentScript/pubpeer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PubPeer {
this.type = "";
this.publicationIds = [];
this.publications = [];
this.pubpeerUrls = [];
this.uriEncodedUrls = {};
this.pageUrls = this.extractValidUrls();
this.uriEncodedDOIs = {};
Expand Down Expand Up @@ -145,7 +146,7 @@ class PubPeer {
};

let param = {
version: "1.6.0",
version: "1.6.2",
browser: Browser.name,
urls: this.pageUrls,
};
Expand Down Expand Up @@ -205,16 +206,31 @@ class PubPeer {
break;
}
this.initTopBarRemoveEvent();
this.initHeaderSubContentToggleEvent();
}

initHeaderSubContentToggleEvent() {
const toggleElement = document.getElementById("pubpeer-toggle-subcontent");
if (toggleElement) {
toggleElement.onclick = function () {
const subContent = document.getElementById("pubpeer-header-subcontent");
if (subContent) {
subContent.style.display =
subContent.style.display === "none" ? "block" : "none";
}
};
}
}

initTopBarRemoveEvent() {
const closeElement = document.getElementById(
"btn-close-pubpeer-article-summary"
);
if (closeElement) {
const that = this;
closeElement.onclick = function () {
this.parentNode.remove();
this.onAfterRemovingTopBar();
this.parentNode.parentNode.remove();
that.onAfterRemovingTopBar();
};
}
}
Expand Down Expand Up @@ -352,9 +368,38 @@ class PubPeer {
`;
}
pElement.innerHTML = `
<img src="${this.url}/img/logo.svg" style="display:inline;vertical-align:middle;padding-right:8px;height:25px;background-color:${bgColor};"></img>
${hrefText}
<div id="btn-close-pubpeer-article-summary" style="float:right;font-size:20px;line-height:24px;padding-right:10px;cursor: pointer;user-select:none;color:white;">×</div>
<div ${
this.publications.length > 1
? 'id="pubpeer-toggle-subcontent" style="cursor: pointer"'
: ""
}>
<img src="${
this.url
}/img/logo.svg" style="display:inline;vertical-align:middle;padding-right:8px;height:25px;background-color:${bgColor};"></img>
${hrefText}
<div id="btn-close-pubpeer-article-summary" style="float:right;font-size:20px;line-height:24px;padding-right:10px;cursor: pointer;user-select:none;color:white;">×</div>
</div>
${
this.publications.length > 1
? `<div id="pubpeer-header-subcontent" style="display: none;">${this.publications.reduce(
(html, publication) => {
html += `
<div>
${Sanitizer.escapeHTML`
<a href="${
publication.url + this.utm
}" target="_blank" rel="noopener noreferrer" style="color:rgb(255,255,255);text-decoration:none;font-weight:500;vertical-align:middle;border: none;">
${publication.title}
</a>
`}
</div>
`;
return html;
},
""
)}</div>`
: ""
}
`;
document.body.prepend(pElement);
this.onAfterAddingTopBar();
Expand Down Expand Up @@ -431,11 +476,14 @@ class PubPeer {
if (publication.title) {
if (!this.publicationIds.includes(publication.id)) {
this.publicationIds.push(publication.id);
this.publications.push(publication);
}
}
}
}
this.validPublicationCount++;
if (!this.pubpeerUrls.includes(publication.url)) {
this.publications.push(publication);
this.pubpeerUrls.push(publication.url);
this.validPublicationCount++;
}
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "PubPeer",
"description": "Show links to existing PubPeer comments",
"version": "1.6.1",
"version": "1.6.2",
"manifest_version": 2,
"author": "Pubpeer Foundation",
"browser_action": {
Expand Down

0 comments on commit f9b5758

Please sign in to comment.