文章分类.js
2.66 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
// ==UserScript==
// @name 文章分类
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://dpcms8.sysu.edu.cn/*/manage/article/add?destination=manage/article
// @match http://dpcms8.sysu.edu.cn/*/manage/article?title=&department_target_id=All&category_target_id=*&promote=All&sticky=All&access_permission_value=All&status=All
// @grant none
// ==/UserScript==
(function($) {
'use strict';
// Your code here...
var ARTICLE_DATA;
function _fill(element, data) {
element.val(data);
}
function _selectOptioin(optionE) {
optionE.siblings().attr('selected', false);
optionE.attr('selected', true);
}
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);
}
$('#edit-category option').each(function(index, e) {
if ($(this).val() == '119') {
_selectOptioin($(this));
}
});
$('#edit-approvers option').each(function(index, e) {
if ($(this).val() == '69') {
_selectOptioin($(this));
}
$('#edit-approvers').trigger("chosen:updated");
});
$('#edit-body-0-format--2 option').each(function(index, e) {
if ($(this).val() == 'full_html') {
_selectOptioin($(this));
}
});
hasStorage('article_data', ARTICLE_DATA);
if (hasStorage('article_data', ARTICLE_DATA) && $('[data-drupal-link-system-path="manage/article/add"]').length > 0) {
var article_data = $.parseJSON(localStorage.getItem('article_data'));
var admin_content = $('#block-ccms-admin-content tbody tr .views-field-title a');
admin_content.each(function() {
var _p = $(this).text();
$.each(article_data.Sheet1, function(index, e) {
if (typeof article_data.Sheet1[index].title != 'undefined') {
if (article_data.Sheet1[index].title == _p) {
article_data.Sheet1[index] = {};
}
}
});
});
localStorage.setItem('article_data', JSON.stringify(article_data));
}
article_data = $.parseJSON(localStorage.getItem('article_data'));
var _title = '';
var _misc = '';
$.each(article_data.Sheet1, function(index, e) {
if (typeof article_data.Sheet1[index].title != 'undefined') {
_title = article_data.Sheet1[index].title;
_misc = article_data.Sheet1[index].misc;
return false;
}
});
_misc = /:(.*) 作者/.exec(_misc)[1];
_fill($('#edit-title-0-value'), _title);
_fill($('#edit-origin-0-value'), _misc);
})(jQuery);