Skip to content

Instantly share code, notes, and snippets.

@mashiro
Last active March 5, 2021 08:52
Show Gist options
  • Save mashiro/cbe6e9165b43196d6c54db87bca7d4dd to your computer and use it in GitHub Desktop.
Save mashiro/cbe6e9165b43196d6c54db87bca7d4dd to your computer and use it in GitHub Desktop.
BookLive! の作品ページでフォロー解除ができるようにするブックマークレット
javascript:(function(){var e=function(){var c,a,b;return null==(a=null==(c=document.querySelector("link[rel='canonical']"))?void 0:c.href)?void 0:null==(b=a.match(/title_id\/(\d+)\//))?void 0:b[1]}();null==e?alert("Can't get title-id."):function(c){var a=document.createElement("iframe");a.src="/follow/title-list";document.querySelector("body").appendChild(a);var b=a.contentWindow;b.addEventListener("DOMContentLoaded",function(){var f=b.document.querySelector("#title_list_form input[name='token']").value,d=new FormData;d.append("token",f);d.append("title_id[]",c);d.append("notice_type",1);fetch("/follow/notification-delete",{method:"POST",body:d}).then(function(){location.reload()})})}(e)})();
;(() => {
const getTitleId = () => {
const url = document.querySelector("link[rel='canonical']")?.href
return url?.match(/title_id\/(\d+)\//)?.[1]
}
const deleteNotification = (titleId) => {
const iframe = document.createElement('iframe')
iframe.src = '/follow/title-list'
const body = document.querySelector('body')
body.appendChild(iframe)
const win = iframe.contentWindow
win.addEventListener('DOMContentLoaded', () => {
const token = win.document.querySelector("#title_list_form input[name='token']").value
const data = new FormData()
data.append('token', token)
data.append('title_id[]', titleId)
data.append('notice_type', 1)
fetch('/follow/notification-delete', {
method: 'POST',
body: data,
}).then(() => {
location.reload()
})
})
}
const titleId = getTitleId()
if (titleId == null) {
alert("Can't get title-id.")
return
}
deleteNotification(titleId)
})()
@mashiro
Copy link
Author

mashiro commented Mar 3, 2021

ブックマークレットの登録方法はこのあたりを参照 https://qiita.com/aqril_1132/items/b5f9040ccb8cbc705d04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment