Skip to content

Instantly share code, notes, and snippets.

@Tachibana446
Created May 3, 2018 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tachibana446/afc8d529e06ca90bab54346827db8d81 to your computer and use it in GitHub Desktop.
Save Tachibana446/afc8d529e06ca90bab54346827db8d81 to your computer and use it in GitHub Desktop.
トークの特定ユーザーをミュートするjquery
// ミュートしたいユーザーを入れる
// 例:
var mute_list = [
"6341", "426484", "395518", "368380", "444302", "496247", "517648"
]
$(() => {
// 削除済みの投稿
let deleted_response = []
$("#root div.response-item")
.each((i, item) => {
var is_target_res = false
// 削除済みの投稿に対するレスも削除
$(item).find('div.response-body a').each((j, anchor) => {
let match = $(anchor).text().match(/>>(\d+)/)
if (match && match[1]) {
var target_id = match[1]
if (deleted_response.indexOf(target_id) > -1) {
is_target_res = true
return false
}
}
})
// ミュートしたいユーザーの投稿も削除
let username = $(item).find('a.user')
let temp = $(username).attr('href').match(/profile\/(\d+)/)
let id
if(temp) id = temp[1]
if ((!id || mute_list.indexOf(id) == -1) && !is_target_res) {
return true
}
// 削除
let message = is_target_res ? "対象へのレスなので削除" : "削除"
// Username
let orig_username = $(`<div>${username.html()}</div>`)
orig_username.hide()
orig_username.on('mouseleave', () => orig_username.hide())
let new_username = $(`<div>${message}</div>`)
new_username.on({
'mouseenter': () => orig_username.show()
}, {
'mouseleave': () => orig_username.hide()
})
$(username).html("").append(new_username).append(orig_username)
// Response
let response_body = $(item).find('div.response-body')
let new_message = $(`<div>${message}</div>`)
let show_orig_message_button = $(`<button>表示/非表示</button>`)
let orig_message = $(`<div>${response_body.html()}</div>`)
orig_message.hide()
show_orig_message_button.on('click', () => orig_message.toggle())
response_body.html('').prepend(new_message).prepend(show_orig_message_button).prepend(orig_message)
if (!is_target_res) {
let deleted_id = $(item).attr('id')
deleted_response.push(deleted_id)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment