Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions browse/static/js/plaudit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(async function () {
$output = $('#plauditContainer');
const articleDoi = $output[0].dataset.doi;
const articleTitleElementContent = document
.querySelector("h1.title")
.textContent;
const articleTitle = articleTitleElementContent.startsWith("Title:")
// The `h1.title` has a `span.description` preceding the title that just
// says "Title:", so we'll need to strip that off:
? articleTitleElementContent.substring("Title:".length)
: articleTitleElementContent;

const endorsementsResponse = await fetch(
`https://api.eventdata.crossref.org/v1/events?mailto=arxiv_integration@plaudit.pub&obj-id=${encodeURIComponent(`https://doi.org/${articleDoi}`)}&source=plaudit`
Comment thread
cbf66 marked this conversation as resolved.
);
/**
* @type {{
* status: "ok",
* "message-type": "event-list",
* message: {
* "total-results": number,
* events: Array<{
* obj_id: `https://doi.org/10.${string}`,
* subj_id: `https://orcid.org/${string}`,
* occurred_at: string,
* source_id: "plaudit",
* action: "add",
* }>,
* },
* }}
*/
const endorsementsData = await endorsementsResponse.json();

const endorsements = endorsementsData.message.events.filter(
event => event.source_id === "plaudit" && event.action === "add",
);

const endorsementDescription = document.createElement("p");
endorsementDescription.innerHTML = endorsements.length === 0
? `
<a href="https://plaudit.pub/endorsements/doi:${articleDoi}" target="_blank" rel="noopener noreferrer">
Be the first to endorse <b>${articleTitle}</b>.
</a>`
: `
<a href="https://plaudit.pub/endorsements/doi:${articleDoi}" target="_blank" rel="noopener noreferrer">
View ${endorsements.length} endorsement${endorsements.length > 0 && "s"} of <b>${articleTitle}</b>, or add your own.
</a>`
$output.append(endorsementDescription);
})();
7 changes: 7 additions & 0 deletions browse/static/js/toggle-labs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $(document).ready(function() {
"influenceflower": $('#influenceflower-toggle').data('script-url'),
"sciencecast": $('#sciencecast-toggle').data('script-url'),
"gotitpub": $('#gotitpub-toggle').data('script-url'),
"plaudit": $('#plaudit-toggle').data('script-url'),
"alphaxiv": $('#alphaxiv-toggle').data('script-url'),
"bibex": {
"url": $('#bibex-toggle').data('script-url'),
Expand Down Expand Up @@ -77,6 +78,10 @@ $(document).ready(function() {
$.cachedScript(scripts["paperwithcode"]).done(function(script, textStatus) {
console.log(textStatus);
});
} else if (key == "plaudit-toggle") {
$.cachedScript(scripts["plaudit"]).done(function(script, textStatus) {
console.log(textStatus);
});
} else if (key === "replicate-toggle") {
$.cachedScript(scripts["replicate"]).done(function(script, textStatus) {
// console.log(textStatus, "replicate (on cookie check)");
Expand Down Expand Up @@ -192,6 +197,8 @@ $(document).ready(function() {
$.cachedScript(scripts["paperwithcode"]).done(function(script, textStatus) {
console.log(textStatus);
});
} else if ($(this).attr("id") == "plaudit-toggle") {
$.cachedScript(scripts["plaudit"]).done(function(script, textStatus) {});
} else if ($(this).attr("id") == "replicate-toggle") {
$.cachedScript(scripts["replicate"]).done(function(script, textStatus) {
// console.log(textStatus, "replicate (on lab toggle)");
Expand Down
25 changes: 25 additions & 0 deletions browse/templates/abs/labs_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ <h1>Code, Data and Media Associated with this Article</h1>
<div id="sciencecast-output" style="display:none"></div>
<div id="huggingface-output" style="display:none"></div>
</div>
{%- if abs_meta.doi -%}
<input type="radio" name="tabs" id="tabfive">
<label for="tabfive">Endorsements</label>
<div class="tab">
<h1>Endorsements</h1>
<div class="toggle">
<div class="columns is-mobile lab-row">
<div class="column lab-switch">
<label class="switch">
<input
id="plaudit-toggle"
data-script-url="{{ url_for('static', filename='js/plaudit.js') }}"
type="checkbox" class="lab-toggle" aria-labelledby="label-for-plaudit">
<span class="slider"></span>
<span class="is-sr-only">Plaudit endorsements toggle</span>
</label>
</div>
<div class="column lab-name">
<span id="label-for-plaudit">Plaudit endorsements</span> <em>(<a href="https://labs.arxiv.org/">What is Plaudit?</a>)</em>
</div>
</div>
</div>
<div id="plauditContainer" data-doi="{{ abs_meta.doi }}"></div>
</div>
{% endif %}


<input type="radio" name="tabs" id="labstabs-demos-input">
Expand Down