diff --git a/static/scripts.js b/static/scripts.js index a3dd274..f8c57ac 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -71,4 +71,23 @@ diff.forEach(function(part){ left.appendChild(left_fragment); right.appendChild(right_fragment); -} \ No newline at end of file +} + + +// 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 = ' (deleted)'; + +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); +}) \ No newline at end of file