Last active
August 29, 2015 14:07
-
-
Save poke/d1fd6b5227efc5885cac to your computer and use it in GitHub Desktop.
[User script] StackExchange Chat: Unstar from transcript
This file contains hidden or 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== | |
// @id stackexchange-chat-unstar-transcript@poke | |
// @name StackExchange Chat: Unstar from transcript | |
// @namespace poke | |
// @version 1.0.0 | |
// @author Patrick Westerhoff | |
// @include http://chat.stackoverflow.com/transcript/* | |
// @homepageURL https://gist.github.com/poke/d1fd6b5227efc5885cac | |
// @updateURL https://gist.githubusercontent.com/poke/d1fd6b5227efc5885cac/raw/stackexchange-chat-unstar-transcript.user.js | |
// @run-at document-end | |
// ==/UserScript== | |
(function () { | |
var fkey = 'fkey=' + document.querySelector("input[name='fkey']").value; | |
Array.prototype.forEach.call(document.querySelectorAll('.message'), function (message) { | |
var id = message.id.substring(8); | |
var link = message.querySelector('a'); | |
var stars = message.querySelector('.flash .stars'); | |
if (stars) { | |
stars.title = 'Cancel all stars'; | |
stars.style.cursor = 'pointer'; | |
stars.addEventListener('click', function () { | |
if (confirm('Do you want to cancel all stars?')) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('post', '/messages/' + id + '/unstar', true); | |
xhr.onload = function () { | |
window.location.href = link; | |
}; | |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
xhr.send(fkey); | |
} | |
}); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment