-
-
Save rlemon/ef65a1a5fa2bf3fcae4c to your computer and use it in GitHub Desktop.
easy access control
This file contains 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== | |
// @name Easy Access Control | |
// @author Robert Lemon | |
// @version 1.0 | |
// @namespace | |
// @description Adds an access control button to the chat. | |
// @include http://chat.stackoverflow.com/rooms/*/* | |
// ==/UserScript== | |
function exec(fn) { | |
var script = document.createElement('script'); | |
script.setAttribute("type", "application/javascript"); | |
script.textContent = '(' + fn + ')();'; | |
document.body.appendChild(script); // run the script | |
} | |
// script injection | |
exec(function () { | |
var roomId = Number(/\d+/.exec(location)[0]); | |
$.ajax({ | |
url: '/rooms/' + roomId, | |
success: function (page) { | |
var access = $(page).find('.sprite-sec-gallery').length; | |
var btn = $('<a href="#"></a>'); | |
btn.text(access ? 'unlock' : 'lock'); | |
btn.on('click', function () { | |
$.post('/rooms/save', { | |
roomId: roomId, | |
defaultAccess: access ? 'read-write' : 'read-only', | |
fkey: fkey().fkey | |
}); | |
return false; | |
}); | |
$('<span> | </span>').add(btn).appendTo($('#sidebar-menu')); | |
}, | |
error: function () { | |
console.log('access control plugin failed to load'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment