自动同步.js
2.59 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
// ==UserScript==
// @name New Userscript
// @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;
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;
});
return settingObj;
}
function hasStorage(name, date) {
if (typeof localStorage.getItem(name) != 'string') {
localStorage.setItem(name, JSON.stringify(date));
}
return !!localStorage.getItem(name);
}
hasStorage('menu_date', MENU_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 ($('#edit-name-0-value').length > 0 && hasStorage('menu_date', MENU_DATE)) {
var JSON_MENU_LIST = $.parseJSON(localStorage.getItem('menu_date'));
var settingObj = storageOper('menu_date', JSON_MENU_LIST);
$('#edit-name-0-value').val(settingObj.title);
if (settingObj.hasOwnProperty('parent')) {
$('#edit-parent option').each(function() {
if ($(this).text() == settingObj.parent) {
$('#edit-parent option').attr('selected', false);
$(this).attr('selected', true);
}
});
}
$('#edit-submit').trigger('click');
}
if ($('#edit-title-0-value').length > 0 && $('#edit-link-0-uri').length > 0 && hasStorage('menu_date', MENU_DATE)) {
JSON_MENU_LIST = $.parseJSON(localStorage.getItem('menu_date'));
settingObj = storageOper('menu_date', JSON_MENU_LIST);
$('#edit-link-0-uri').val('/');
$('#edit-title-0-value').val(settingObj.title);
if (settingObj.hasOwnProperty('parent')) {
$('#edit-menu-parent option').each(function() {
if ($(this).text().indexOf(settingObj.parent) > 0) {
$('#edit-parent option').attr('selected', false);
$(this).attr('selected', true);
$('#edit-menu-parent').trigger("chosen:updated");
}
});
}
//$('#edit-submit').trigger('click');
}
})(jQuery);