Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var bookmarlet = {
- location: window.location,
- url: {},
- params: {},
- toggleParams: function(obj) {
- var bool = false;
- if (this.params[obj.param] !== '' && this.params[obj.param] !== undefined) {
- bool = true;
- }
- this.doUrl({
- prop: obj.param,
- value: obj.value
- }, bool);
- },
- toggleInput: function(obj) {
- var bool = false;
- if (this.params[obj.param] !== '' && this.params[obj.param] !== undefined) {
- bool = true;
- } else {
- obj.value = prompt(obj.value);
- }
- this.doUrl({
- prop: obj.param,
- value: obj.value
- }, bool);
- },
- toggleNoParams: function(param) {
- var bool = false;
- if (this.params[param] === '') {
- bool = true;
- }
- this.doUrl({
- prop: param
- }, bool);
- },
- doUrl: function(config, bool) {
- this.location.href = [this.location.origin, this.location.pathname, this.rebuildParams(config, bool)].join('');
- },
- rebuildParams: function(item, deleteIt) {
- if (deleteIt) {
- delete this.params[item.prop];
- } else {
- this.params[item.prop] = item.value !== undefined ? item.value : '';
- }
- var search = '?',
- propArray = [],
- str = '';
- for (var prop in this.params) {
- console.log(prop, this.params[prop]);
- str = prop;
- if (this.params[prop] !== '') {
- str += '=' + this.params[prop];
- }
- propArray.push(str);
- }
- search += propArray.join('&');
- if (search != '?') {
- return search;
- }
- return '';
- },
- parseURL: function() {
- this.url = {
- protocol: this.location.protocol.replace(':', ''),
- host: this.location.hostname,
- port: this.location.port,
- query: this.location.search,
- params: this.parseParams(),
- file: (this.location.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
- hash: this.location.hash.replace('#', ''),
- path: this.location.pathname.replace(/^([^\/])/, '/$1'),
- relative: (this.location.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
- segments: this.location.pathname.replace(/^\//, '').split('/')
- };
- this.params = this.url.params;
- },
- parseParams: function() {
- var ret = {},
- seg = this.location.search.replace(/^\?/, '').split('&'),
- len = seg.length,
- i = 0,
- s;
- for (; i < len; i++) {
- if (!seg[i]) {
- continue;
- }
- s = seg[i].split('=');
- if (s[1] === undefined) {
- s[1] = '';
- }
- ret[s[0]] = s[1];
- }
- return ret;
- }
- };
- bookmarlet.parseURL();
- bookmarlet.toggleParams({
- param: 'wcmmode',
- value: 'disabled'
- })
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement