自动同步.js
5.08 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// ==UserScript==
// @name 栏目 基本页 菜单
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://*/*
// @grant none
// ==/UserScript==
(function($) {
'use strict';
// Your code here...
var MENU_DATE = {};
var TAXONOMY_DATE = {};
var NODE_DATE = {};
var TAXONOMY_INIT_DATE = {};
var NODE_INIT_DATE = {};
function hasStorage(name, date) {
if (JSON.stringify(date) === '{}') {
return false;
}
if (typeof localStorage.getItem(name) != 'string') {
localStorage.setItem(name, JSON.stringify(date));
}
return !!localStorage.getItem(name);
}
function storageOper(_cookieName, obj) {
var settingObj = {};
$.each(obj, function(index, arr) {
if (obj[index].hasOwnProperty('parent')) {
settingObj.parent = obj[index].parent;
}
settingObj.title = obj[index].title;
delete obj[index];
localStorage.setItem(_cookieName, JSON.stringify(obj));
return false;
});
var toxonomy_link_obj = $.parseJSON(localStorage.getItem('toxonomy_link_date'));
var node_link_obj = $.parseJSON(localStorage.getItem('node_link_date'));
$.each(toxonomy_link_obj, function(index, arr) {
if (toxonomy_link_obj[index].taxonomy == settingObj.title) {
settingObj.url = toxonomy_link_obj[index].url;
delete toxonomy_link_obj[index];
}
});
$.each(node_link_obj, function(index, arr) {
if (node_link_obj[index].node == settingObj.title) {
settingObj.nid = node_link_obj[index].url;
delete node_link_obj[index];
}
});
return settingObj;
}
hasStorage('menu_date', MENU_DATE);
hasStorage('toxonomy_link_date', TAXONOMY_INIT_DATE);
hasStorage('node_link_date', NODE_INIT_DATE);
if ($('#taxonomy .menu-item__link').length > 0) {
$('#taxonomy .menu-item__link').each(function(index) {
TAXONOMY_INIT_DATE[index] = {
'taxonomy': $(this).text(),
'url': /[0-9]*$/.exec($(this).attr('href'))[0]
};
});
localStorage.setItem('toxonomy_link_date', JSON.stringify(TAXONOMY_INIT_DATE));
}
if ($('.view-id-manage_page').length > 0) {
$('.footable tbody tr').each(function(index) {
NODE_INIT_DATE[index] = {
'node': $(this).find('.views-field-title a').text(),
'url': $(this).find('.views-field-nid').text().trim(),
};
});
localStorage.setItem('node_link_date', JSON.stringify(NODE_INIT_DATE));
}
if ($('[data-drupal-link-system-path="manage/department/add"]').length > 0) {
$('[data-drupal-link-system-path="manage/department/add"]')[0].click();
}
if ($('[data-drupal-link-system-path="admin/structure/menu/manage/main/add"]').length > 0) {
$('[data-drupal-link-system-path="admin/structure/menu/manage/main/add"]')[0].click();
}
if ($('[data-drupal-link-system-path="manage/page/add"]').length > 0) {
$('[data-drupal-link-system-path="manage/page/add"]')[0].click();
}
//栏目
if ($('.taxonomy-term-department-form #edit-name-0-value').length > 0 && hasStorage('taxonomy_date', TAXONOMY_DATE)) {
var settingObj = storageOper('taxonomy_date', $.parseJSON(localStorage.getItem('taxonomy_date')));
$('#edit-name-0-value').val(settingObj.title);
if (settingObj.hasOwnProperty('parent')) {
$('#edit-parent option').each(function() {
if ($(this).text().trim() == settingObj.parent.trim()) {
$('#edit-parent option').attr('selected', false);
$(this).attr('selected', true);
}
});
}
$('#edit-submit').trigger('click');
}
//基本页
if ($('.node-page-form #edit-title-0-value').length > 0 && hasStorage('node_date', NODE_DATE)) {
var NodesettingObj = storageOper('node_date', $.parseJSON(localStorage.getItem('node_date')));
$('#edit-title-0-value').val(NodesettingObj.title);
$('#edit-moderation-state-published').trigger('click');
}
//菜单
if ($('#edit-title-0-value').length > 0 && $('#edit-link-0-uri').length > 0 && hasStorage('menu_date', MENU_DATE) && ((JSON.stringify(localStorage.getItem('toxonomy_link_date')) !== '{}') || (JSON.stringify(localStorage.getItem('node_link_date')) !== '{}'))) {
var MenusettingObj = storageOper('menu_date', $.parseJSON(localStorage.getItem('menu_date')));
$('#edit-link-0-uri').val('/');
$('#edit-title-0-value').val(MenusettingObj.title);
if (MenusettingObj.hasOwnProperty('parent')) {
$('#edit-menu-parent option').each(function() {
if ($(this).text().indexOf(MenusettingObj.parent) > 0) {
$('#edit-parent option').attr('selected', false);
$(this).attr('selected', true);
$('#edit-menu-parent').trigger("chosen:updated");
}
});
}
if (MenusettingObj.hasOwnProperty('url')) {
$('#edit-link-0-uri').val('/taxonomy/term/' + MenusettingObj.url);
} else if (MenusettingObj.hasOwnProperty('nid')) {
$('#edit-link-0-uri').val('/basic/' + MenusettingObj.nid);
} else {
$('#edit-link-0-uri').val('/');
}
$('#edit-submit').trigger('click');
}
})(jQuery);