Commit cfd346ff375682debd160e1f579736b7be2cc3e5

Authored by muyulingshi
1 parent 3e02b2e6

rm bug

  1 +(function ($) {
  2 + var TAXONNOMY_LINK_LIST = {};
  3 + $('#taxonomy .menu-item__link').each(function (index) {
  4 + TAXONNOMY_LINK_LIST[index] = {
  5 + 'taxonomy':$(this).text(),
  6 + 'url':/[0-9]*$/.exec($(this).attr('href'))[0]
  7 + };
  8 + });
  9 +
  10 + console.log(JSON.stringify(TAXONNOMY_LINK_LIST));
  11 +
  12 +})(jQuery)
... ...
... ... @@ -9,100 +9,112 @@
9 9 // ==/UserScript==
10 10
11 11 (function($) {
12   - 'use strict';
13   -
14   - // Your code here...
15   - var MENU_DATE = {},
16   - TAXONOMY_DATE = {},
17   - NODE_DATE = {},
18   - TAXONOMY_INIT_DATE = {},
19   - NODE_INIT_DATE = {};
20   -
21   - function hasStorage(name, date) {
22   - if (JSON.stringify(date) === '{}') {
23   - return false;
24   - }
  12 + 'use strict';
  13 +
  14 + // Your code here...
  15 + var MENU_DATE = {
  16 + '0': {
  17 + 'title': '首页'
  18 + }
  19 + },
  20 + TAXONOMY_DATE = {
  21 + '0': {
  22 + 'title': '首页'
  23 + }
  24 + },
  25 + NODE_DATE = {
  26 + '0': {
  27 + 'title': '首页'
  28 + }
  29 + },
  30 + TAXONOMY_INIT_DATE = {},
  31 + NODE_INIT_DATE = {};
  32 +
  33 + function hasStorage(name, date) {
  34 + if (JSON.stringify(date) === '{}') {
  35 + return false;
  36 + }
25 37
26   - if (typeof localStorage.getItem(name) != 'string') {
27   - localStorage.setItem(name, JSON.stringify(date));
28   - }
  38 + if (typeof localStorage.getItem(name) != 'string') {
  39 + localStorage.setItem(name, JSON.stringify(date));
  40 + }
29 41
30   - return !!localStorage.getItem(name);
31   - }
  42 + return !!localStorage.getItem(name);
  43 + }
32 44
33   - function storageOper(_cookieName, obj) {
34   - var settingObj = {};
  45 + function storageOper(_cookieName, obj) {
  46 + var settingObj = {};
35 47
36   - $.each(obj, function(index, arr) {
37   - if (obj[index].hasOwnProperty('parent')) {
38   - settingObj.parent = obj[index].parent;
39   - }
40   - settingObj.title = obj[index].title;
41   - delete obj[index];
42   - localStorage.setItem(_cookieName, JSON.stringify(obj));
43   - return false;
44   - });
45   -
46   - if (hasStorage('link_date', TAXONOMY_INIT_DATE)) {
47   - var link_obj = $.parseJSON(localStorage.getItem('link_date'));
48   - $.each(link_obj, function(index, arr) {
49   - if (link_obj[index].taxonomy == settingObj.title) {
50   - settingObj.url = link_obj[index].url;
51   - delete link_obj[index];
  48 + $.each(obj, function(index, arr) {
  49 + if (obj[index].hasOwnProperty('parent')) {
  50 + settingObj.parent = obj[index].parent;
52 51 }
  52 + settingObj.title = obj[index].title;
  53 + delete obj[index];
  54 + localStorage.setItem(_cookieName, JSON.stringify(obj));
  55 + return false;
53 56 });
54   - }
55 57
56   - return settingObj;
57   - }
58   -
59   - hasStorage('menu_date', MENU_DATE);
60   - hasStorage('toxonomy_link_date', TAXONOMY_INIT_DATE);
61   - hasStorage('node_link_date', NODE_INIT_DATE);
62   -
63   - if ($('[data-drupal-link-system-path="manage/department/add"]').length > 0) {
64   - $('[data-drupal-link-system-path="manage/department/add"]')[0].click();
65   - }
  58 + if (hasStorage('link_date', TAXONOMY_INIT_DATE)) {
  59 + var link_obj = $.parseJSON(localStorage.getItem('link_date'));
  60 + $.each(link_obj, function(index, arr) {
  61 + if (link_obj[index].taxonomy == settingObj.title) {
  62 + settingObj.url = link_obj[index].url;
  63 + delete link_obj[index];
  64 + }
  65 + });
  66 + }
66 67
67   - if ($('[data-drupal-link-system-path="admin/structure/menu/manage/main/add"]').length > 0) {
68   - $('[data-drupal-link-system-path="admin/structure/menu/manage/main/add"]')[0].click();
69   - }
  68 + return settingObj;
  69 + }
70 70
71   - //栏目
72   - if ($('.taxonomy-term-department-form #edit-name-0-value').length > 0 && hasStorage('taxonomy_date', TAXONOMY_DATE)) {
73   - var settingObj = storageOper('menu_date', $.parseJSON(localStorage.getItem('menu_date')));
  71 + hasStorage('menu_date', MENU_DATE);
  72 + hasStorage('toxonomy_link_date', TAXONOMY_INIT_DATE);
  73 + hasStorage('node_link_date', NODE_INIT_DATE);
74 74
75   - $('#edit-name-0-value').val(settingObj.title);
76   - if (settingObj.hasOwnProperty('parent')) {
77   - $('#edit-parent option').each(function() {
78   - if ($(this).text() == settingObj.parent) {
79   - $('#edit-parent option').attr('selected', false);
80   - $(this).attr('selected', true);
81   - }
82   - });
  75 + if ($('[data-drupal-link-system-path="manage/department/add"]').length > 0) {
  76 + $('[data-drupal-link-system-path="manage/department/add"]')[0].click();
83 77 }
84 78
85   - $('#edit-submit').trigger('click');
86   - }
  79 + if ($('[data-drupal-link-system-path="admin/structure/menu/manage/main/add"]').length > 0) {
  80 + $('[data-drupal-link-system-path="admin/structure/menu/manage/main/add"]')[0].click();
  81 + }
87 82
88   - //基本页
89   - if ($('.node-page-form #edit-name-0-value').length > 0 && hasStorage('node_date', NODE_DATE)) {
90   - var settingObj = storageOper('menu_date', $.parseJSON(localStorage.getItem('menu_date')));
  83 + //栏目
  84 + if ($('.taxonomy-term-department-form #edit-name-0-value').length > 0 && hasStorage('taxonomy_date', TAXONOMY_DATE)) {
  85 + var settingObj = storageOper('taxonomy_date', $.parseJSON(localStorage.getItem('taxonomy_date')));
  86 +
  87 + $('#edit-name-0-value').val(settingObj.title);
  88 + if (settingObj.hasOwnProperty('parent')) {
  89 + $('#edit-parent option').each(function() {
  90 + if ($(this).text() == settingObj.parent) {
  91 + $('#edit-parent option').attr('selected', false);
  92 + $(this).attr('selected', true);
  93 + }
  94 + });
  95 + }
91 96
92   - $('#edit-name-0-value').val(settingObj.title);
93   - if (settingObj.hasOwnProperty('parent')) {
94   - $('#edit-parent option').each(function() {
95   - if ($(this).text() == settingObj.parent) {
96   - $('#edit-parent option').attr('selected', false);
97   - $(this).attr('selected', true);
98   - }
99   - });
  97 + $('#edit-submit').trigger('click');
100 98 }
101 99
102   - $('#edit-submit').trigger('click');
103   - }
104   - //菜单
105   - 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')) !== '{}'))) {
  100 + //基本页
  101 + if ($('.node-page-form #edit-name-0-value').length > 0 && hasStorage('node_date', NODE_DATE)) {
  102 + var NodesettingObj = storageOper('node_date', $.parseJSON(localStorage.getItem('node_date')));
  103 +
  104 + $('#edit-name-0-value').val(NodesettingObj.title);
  105 + if (NodesettingObj.hasOwnProperty('parent')) {
  106 + $('#edit-parent option').each(function() {
  107 + if ($(this).text() == NodesettingObj.parent) {
  108 + $('#edit-parent option').attr('selected', false);
  109 + $(this).attr('selected', true);
  110 + }
  111 + });
  112 + }
  113 +
  114 + $('#edit-submit').trigger('click');
  115 + }
  116 + //菜单
  117 + 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')) !== '{}')) {
106 118 var MenusettingObj = storageOper('menu_date', $.parseJSON(localStorage.getItem('menu_date')));
107 119
108 120 $('#edit-link-0-uri').val('/');
... ...
Please register or login to post a comment