Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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