Jump to content

User:Suffusion of Yellow/vpt-mockup.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Proof concept only. Not intended for actual use!
// <nowiki>
$(function() {
	'use strict';
	var info = {
		"user-agent": {
			dangerous: true,
			get: function() {
				return window.navigator.userAgent;
			}
		},
		"screen-resolution": {
			dangerous: true,
			get: function() {
				return window.screen.width + "x" + window.screen.height;
			}
		},
		"skin": {
			get: function() {
				return mw.user.options.values.skin;
			}
		},
		"relevant-pages": {
			get: function() {
				var skin = mw.user.options.values.skin;
				var prefix = "User:" + mw.config.get('wgUserName') + "/";

				return '[[' + prefix + 'common.js|commons.js]], ' +
					'[[' + prefix + 'common.css|common.css]], ' +
					'[[' + prefix + skin + '.js|' + skin + '.js]], ' +
					'[[' + prefix + skin + '.css|' + skin + '.css]], ' +
					'[[:meta:' + prefix + 'global.js|global.js]], ' +
					'[[:meta:' + prefix + 'global.css|global.css]]';
			}
		},
		"gadgets": {
			get: function() {
				var gadgets = [];

				for(var opt in mw.user.options.values) {
					if (opt.indexOf("gadget-") === 0)
						gadgets.push(opt.slice(7));
				}

				return gadgets.join(", ");
			}
		}
	};

	if (mw.config.get('wgPageName') === "Special:BlankPage/TechInfo") {
		var $content = $('#mw-content-text').html("");
		var basic = "";
		var dangerous = "";

		for(var name in info)
			if (info.hasOwnProperty(name)) {
				var result;
				try {
					result = info[name].get();
				} catch(e) {
					result = "unknown";
				}
				var line = "* " + name + ": " + result + "\n";

				if (info[name].dangerous)
					dangerous += line;
				else
					basic += line;
			}

		$content.append("<h2>Usually safe to share<h/2>");
		var $basic = $("<textarea></textarea>", {
			rows: 20,
			readonly: true
		});
		$basic.val(basic).appendTo($content);

		$content.append("<h2>Possibly unsafe to share</h2>");
		$content.append("<div>This information may be <a href='https://panopticlick.eff.org'>used to track you</a> on the web.</div>");

		var $dangerous = $("<textarea></textarea>", {
			rows: 5,
			readonly: true
		});
		$dangerous.val(dangerous).appendTo($content);
	}
});
//</nowiki>