-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminBookmarklet.js
135 lines (117 loc) · 3.25 KB
/
adminBookmarklet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*!
* adminBookmarklet v3.0
* Dynamic Bookmarklet to quickly access the backend of your tool
*
* Copyright (c) 2018 - Tom Lutzenberger (lutzenbergerthomas at gmail dot com)
* https://github.com/tomlutzenberger/adminBookmarklet
* https://tomlutzenberger.github.io/adminBookmarklet/
*
* @license: Licensed under the MIT license
* https://github.com/tomlutzenberger/adminBookmarklet/blob/master/LICENSE
*/
/* globals document,window */
/* jslint esnext:true */
/**
* @method adminBookmarklet
* @description Main object holding all methods
*
* @return {Object} Public object methods
*/
const adminBookmarklet = () => {
'use strict';
/**
* @property ZERO
* @description Constant representing the number zero
*
* @type {Integer}
*/
const ZERO = 0;
/**
* @property FIRST
* @description Constant representing the first index of every array
*
* @type {Integer}
*/
const FIRST = 0;
/**
* @method getSystems
* @description Get a mapping of all supported systems and corresponding paths
*
* @return {Object[]}
*/
const getSystems = () => {
return [
{
name: 'cloudrexx',
path: 'cadmin',
},
{
name: 'drupal',
path: 'user',
},
{
name: 'jimdo',
path: 'login',
},
{
name: 'joomla',
path: 'administrator',
},
{
name: 'magento',
path: 'admin',
},
{
name: 'pimcore',
path: 'admin',
},
{
name: 'sefrengo',
path: 'backend',
},
{
name: 'typo3',
path: 'typo3',
},
{
name: 'weebly',
path: 'login',
},
{
name: 'wordpress',
path: 'wp-admin',
},
{
name: 'xt-commerce',
path: 'login.php',
},
];
};
/**
* @method parseHead
* @description Parse the current document's `<head>` HTML and return it without whitespaces
*
* @return {String} The HTML
*/
const parseHead = () => {
/* Select the content of <head>, strip all whitespaces and return */
const head = document.getElementsByTagName('head')[FIRST].innerHTML;
return head.replace(/\s/g, '');
};
/**
* @method getAdminPath
* @description Get the admin path depending on detected system or `admin` as default
*
* @return {String} Admin path
*/
const getAdminPath = () => {
const headContent = parseHead();
const system = getSystems().filter((systemObj) => {
const pattern = new RegExp(systemObj.name, 'im');
return pattern.test(headContent);
});
return system.length > ZERO ? system[FIRST].path : 'admin';
};
return { getSystems, parseHead, getAdminPath };
};
window.open(window.location.protocol + '//' + window.location.host + '/' + adminBookmarklet().getAdminPath(), '_blank');