Commit 18b6281bc8bb4b4a7b74251b10844e64ac03e3e1

Authored by muyulingshi
0 parents

init

  1 +{
  2 + "0": {
  3 + "title": "首页"
  4 + },
  5 + "1": {
  6 + "title": "学院概况"
  7 + },
  8 + "2": {
  9 + "title": "院长致辞",
  10 + "parent": "学院概况"
  11 + },
  12 + "3": {
  13 + "title": "发展历程",
  14 + "parent": "学院概况"
  15 + },
  16 + "4": {
  17 + "title": "现任领导",
  18 + "parent": "学院概况"
  19 + }
  20 +}
  1 +// ==UserScript==
  2 +// @name New Userscript
  3 +// @namespace http://tampermonkey.net/
  4 +// @version 0.1
  5 +// @description try to take over the world!
  6 +// @author You
  7 +// @match http://*/*
  8 +// @grant none
  9 +// ==/UserScript==
  10 +
  11 +(function($) {
  12 + 'use strict';
  13 +
  14 + // Your code here...
  15 + var MENU_DATE = {
  16 + "0": {
  17 + "title": "首页"
  18 + },
  19 + "1": {
  20 + "title": "学院概况"
  21 + },
  22 + }
  23 +
  24 + function cookieOper(_cookieName, obj) {
  25 + var settingObj = {};
  26 +
  27 + $.each(obj, function(index, arr) {
  28 + settingObj.title = obj[index].title;
  29 + delete obj[index];
  30 + $.cookie(_cookieName, JSON.stringify(obj));
  31 + return false;
  32 + });
  33 +
  34 + return settingObj;
  35 + }
  36 +
  37 + function hasCookie(name, date) {
  38 + if (!($.cookie(name))) {
  39 + $.cookie(name, JSON.stringify(date));
  40 + }
  41 +
  42 + return !!$.cookie(name);
  43 + }
  44 + hasCookie('menu_date', MENU_DATE);
  45 +
  46 + if ($('[data-drupal-link-system-path="manage/department/add"]').length > 0) {
  47 + $('[data-drupal-link-system-path="manage/department/add"]')[0].click();
  48 + }
  49 +
  50 + if ($('#edit-name-0-value').length > 0 && hasCookie('menu_date', MENU_DATE)) {
  51 + var JSON_MENU_LIST = $.parseJSON($.cookie('menu_date'));
  52 + var settingObj = cookieOper('menu_date', JSON_MENU_LIST);
  53 +
  54 + if (settingObj) {
  55 + $('#edit-name-0-value').val(settingObj.title);
  56 + }
  57 +
  58 + $('#edit-submit').trigger('click');
  59 + }
  60 +
  61 +})(jQuery);
  1 +var MENU_DATE = {};
  2 +var num = 0;
  3 +$('.nav > ul > li').each(function(index) {
  4 + MENU_DATE[num] = {
  5 + 'title': $(this).children('a').text()
  6 + };
  7 + num++;
  8 +
  9 + if ($(this).children('ul').length > 0) {
  10 + $(this).children('ul').children('li').each(function(index) {
  11 + MENU_DATE[num] = {
  12 + 'title': $(this).find('a').text(),
  13 + 'parent': $(this).parents('li').children('a').text()
  14 + };
  15 + num++;
  16 + });
  17 + }
  18 +});
  19 +console.log(JSON.stringify(MENU_DATE));
Please register or login to post a comment