Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. (function() {
  2. var bookmarlet = {
  3. location: window.location,
  4. url: {},
  5. params: {},
  6. toggleParams: function(obj) {
  7. var bool = false;
  8. if (this.params[obj.param] !== '' && this.params[obj.param] !== undefined) {
  9. bool = true;
  10. }
  11. this.doUrl({
  12. prop: obj.param,
  13. value: obj.value
  14. }, bool);
  15. },
  16. toggleInput: function(obj) {
  17. var bool = false;
  18. if (this.params[obj.param] !== '' && this.params[obj.param] !== undefined) {
  19. bool = true;
  20. } else {
  21. obj.value = prompt(obj.value);
  22. }
  23. this.doUrl({
  24. prop: obj.param,
  25. value: obj.value
  26. }, bool);
  27. },
  28. toggleNoParams: function(param) {
  29. var bool = false;
  30. if (this.params[param] === '') {
  31. bool = true;
  32. }
  33. this.doUrl({
  34. prop: param
  35. }, bool);
  36. },
  37. doUrl: function(config, bool) {
  38. this.location.href = [this.location.origin, this.location.pathname, this.rebuildParams(config, bool)].join('');
  39. },
  40. rebuildParams: function(item, deleteIt) {
  41. if (deleteIt) {
  42. delete this.params[item.prop];
  43. } else {
  44. this.params[item.prop] = item.value !== undefined ? item.value : '';
  45. }
  46. var search = '?',
  47. propArray = [],
  48. str = '';
  49. for (var prop in this.params) {
  50. console.log(prop, this.params[prop]);
  51. str = prop;
  52. if (this.params[prop] !== '') {
  53. str += '=' + this.params[prop];
  54. }
  55. propArray.push(str);
  56. }
  57. search += propArray.join('&');
  58. if (search != '?') {
  59. return search;
  60. }
  61. return '';
  62. },
  63. parseURL: function() {
  64. this.url = {
  65. protocol: this.location.protocol.replace(':', ''),
  66. host: this.location.hostname,
  67. port: this.location.port,
  68. query: this.location.search,
  69. params: this.parseParams(),
  70. file: (this.location.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
  71. hash: this.location.hash.replace('#', ''),
  72. path: this.location.pathname.replace(/^([^\/])/, '/$1'),
  73. relative: (this.location.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
  74. segments: this.location.pathname.replace(/^\//, '').split('/')
  75. };
  76. this.params = this.url.params;
  77. },
  78. parseParams: function() {
  79. var ret = {},
  80. seg = this.location.search.replace(/^\?/, '').split('&'),
  81. len = seg.length,
  82. i = 0,
  83. s;
  84. for (; i < len; i++) {
  85. if (!seg[i]) {
  86. continue;
  87. }
  88. s = seg[i].split('=');
  89. if (s[1] === undefined) {
  90. s[1] = '';
  91. }
  92. ret[s[0]] = s[1];
  93. }
  94. return ret;
  95. }
  96. };
  97. bookmarlet.parseURL();
  98. bookmarlet.toggleParams({
  99. param: 'wcmmode',
  100. value: 'disabled'
  101. })
  102. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement