Skip to content

Instantly share code, notes, and snippets.

@poke
Last active August 29, 2015 14: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 poke/d1fd6b5227efc5885cac to your computer and use it in GitHub Desktop.
Save poke/d1fd6b5227efc5885cac to your computer and use it in GitHub Desktop.
[User script] StackExchange Chat: Unstar from transcript
// ==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