User:Proteins/addsandboxlink.js

// // Adds link to open the user's sandbox in a new tab // // To use this script, add "importScript('User:Proteins/addsandboxlink.js');" to your monobook.js subpage // under your user page, as you can see at User:Proteins/monobook.js

function addSandboxLink {

var pt_userpage; var userpage_anchors; var userpage_href = ""; var user_sandbox_href = "";

pt_userpage = document.getElementById('pt-userpage'); if (!pt_userpage) { window.alert("Unable to find pt-userpage."); return; } //	window.alert("Found pt-userpage.");

userpage_anchors = pt_userpage.getElementsByTagName("A"); if (!userpage_anchors) { window.alert("Unable to find userpage anchors."); return; } //	window.alert("Found userpage anchors.");

userpage_href = userpage_anchors[0].href; if (!userpage_href) { window.alert("Unable to find userpage_href."); return; } //	window.alert("Found userpage_href: " + userpage_href);

user_sandbox_href = userpage_href + "/Sandbox"; //	window.alert("Sandbox URL: " + user_sandbox_href);

window.open(user_sandbox_href); window.alert("Opened user sandbox successfully\n\nURL: " + user_sandbox_href); return;

} // closes function addSandboxLink

$(function { mw.util.addPortletLink('p-personal', 'javascript:addSandboxLink', 'my sandbox', 'ca-sandbox', 'Open user sandbox for editing', '5', ''); }); //