Skip to content

Commit

Permalink
Indicate post deletion with JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep committed Sep 5, 2020
1 parent 8866b27 commit 7e20f5a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion static/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ diff.forEach(function(part){

left.appendChild(left_fragment);
right.appendChild(right_fragment);
}
}


// add (deleted) if a post has been deleted
const apiKey = 'YNIhT*kUiXt*Rp*pDBTBnA((';
const filter = '!-.HCX)kdt*(H';
const sitename = 'stackoverflow';
const apiUrl = 'https://api.stackexchange.com/2.2/posts/';
const plagiarisedPostAnchor = document.querySelector('h2 a');
const plagiarisedPostId = plagiarisedPostAnchor.href.split('/')[4];
const originalPostAnchor = document.querySelectorAll('h2 a')[1];
const originalPostId = originalPostAnchor.href.split('/')[4];
const postIds = `${plagiarisedPostId};${originalPostId}`;
const deletedSpan = ' <span class="text-danger">(deleted)</span>';

fetch(`${apiUrl}${postIds}?site=${sitename}&filter=${filter}&key=${apiKey}`).then(response => response.json()).then(jsonResponse => {
const findPostId = id => jsonResponse.items.find(item => item.post_id == id);
if (!findPostId(plagiarisedPostId)) plagiarisedPostAnchor.parentElement.insertAdjacentHTML('afterend', deletedSpan);
if (!findPostId(originalPostId)) originalPostAnchor.parentElement.insertAdjacentHTML('afterend', deletedSpan);
})

0 comments on commit 7e20f5a

Please sign in to comment.