Last active
May 25, 2022 06:57
-
-
Save mh61503891/f7706b260e3acc467e37a89dc703cd7e to your computer and use it in GitHub Desktop.
Remove LGTMs on Qiita
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Remove LGTMs on Qiita | |
// @namespace Violentmonkey Scripts | |
// @match https://qiita.com/* | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @run-at document-idle | |
// @version 2.0 | |
// @description NOTE: This script only works on the page displayed circle-button of LGTM. Please open the entry page on a full-width size display. | |
// ==/UserScript== | |
function add_bookmarks(uri, title) { | |
let bookmarks = GM_getValue('bookmarks', {}); | |
bookmarks[uri] = title; | |
GM_setValue('bookmarks', bookmarks); | |
} | |
if (location.href.match(/qiita\.com\/.+?\/lgtms/)) { | |
GM_setValue('like_index_uri', location.href); | |
var item = document.evaluate("//a[@class='LgtmArticleList__ArticleTitle-y1h1e7-9 gwUuZt']", document.body, null, XPathResult.ANY_TYPE, null).iterateNext(); | |
if (item !== null) { | |
location.href = item.href; | |
} | |
} else if (location.href.match(/qiita\.com\/.+?\/items\/.+?/)) { | |
let like_index_uri = GM_getValue('like_index_uri', null); | |
if (like_index_uri === null) { | |
return; | |
} | |
var item = document.evaluate("//div[@class='it-Actions_item it-Actions_item-like liked likable']/button", document.body, null, XPathResult.ANY_TYPE, null).iterateNext(); | |
if (item !== null) { | |
add_bookmarks(location.href, document.title); | |
item.click(); | |
} | |
location.href = like_index_uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment