Skip to content

Instantly share code, notes, and snippets.

@theefer
Last active December 23, 2015 01:39
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 theefer/6562209 to your computer and use it in GitHub Desktop.
Save theefer/6562209 to your computer and use it in GitHub Desktop.
Polish
<input type="text" placeholder="Your Google Music account" size="30"
id="gmusic-switcher-account"
onkeyup="
(function() {
var account = document.getElementById('gmusic-switcher-account').value;
var bookmarklet = document.getElementById('gmusic-switcher-bookmarklet');
var hrefTemplate = bookmarklet.getAttribute('data-href');
var email;
if (validEmail(account)) {
email = account;
bookmarklet.style.display = 'block';
bookmarklet.textContent = 'Switch Google Music using ' + account;
bookmarklet.href = hrefTemplate.replace('YOUR_EMAIL', email);
} else {
email = '';
bookmarklet.style.display = 'none';
bookmarklet.href = null;
}
function validEmail(s) {
return /[a-z0-9._]+@[a-z0-9._]+\.[a-z]+/.test(s.toLowerCase());
}
})()
"/>
<a data-href="javascript:
(function() { /* IIFE to avoid polluting window */
/* Configuration: the Google Account you subscribed to Google Music with,
will be substituted by the wrapper page */
var email = 'YOUR_EMAIL';
/* Helpers */
var forEach = Array.prototype.forEach.call;
var filter = Array.prototype.filter.call;
/* Dismiss modal window */
var modals = document.querySelectorAll('.signup-flow, .signup-flow-bg');
forEach(modals, function(n){ n.remove(); });
var switcher = document.getElementById('gbgs4dn');
if (switcher) {
switcher.click();
/* Find account switcher entry for the correct account */
var accounts = document.querySelectorAll('.gbps3');
var musicAccount = filter(accounts, function(n){ return n.textContent == email; })[0];
/* and activate it if found */
if (musicAccount) {
musicAccount.click();
} else {
alert('Cannot switch to ' + email + '; are you sure you are logged in?');
}
} else {
alert('Cannot find the account switcher. Are you in the right place?');
}
})()
" id="gmusic-switcher-bookmarklet" style="display: none">Please enter the email of your Google Music account</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment