// Generated by CoffeeScript 1.11.1
// ==UserScript==
// @name Bangumi-Rename-Related-Subjects
// @namespace BRRS
// @description Quickly rename all related subjects at the same time.
// @include /^https?:\/\/((bgm|bangumi)\.tv|chii\.in)\/subject\/\d+\/add_related\/subject/
// @version 1.1.3
// @grant none
// ==/UserScript==
// Generated by CoffeScript ;) ;
'use strict';
var Bootstrap, Core, EventBinding, Wcode, formhash, pagesid, platform, platforms, submitCue, templates;
platforms = {
book: [
{
id: 1001,
name: '漫画',
meta: 'Manga'
}, {
id: 1002,
name: '小说',
meta: 'Novel'
}, {
id: 1003,
name: '画集',
meta: 'Book'
}, {
id: 0,
name: '其它',
meta: 'Book'
}
],
anime: [
{
id: 1,
name: 'TV',
meta: 'TVAnime'
}, {
id: 2,
name: 'OVA',
meta: 'OVA'
}, {
id: 3,
name: '剧场版',
meta: 'Movie'
}, {
id: 0,
name: '其它',
meta: 'Anime'
}
],
music: [],
game: [],
real: [
{
id: 1,
name: '日剧',
meta: 'Television'
}, {
id: 2,
name: '欧美剧',
meta: 'Television'
}, {
id: 3,
name: '华语剧',
meta: 'Television'
}, {
id: 0,
name: '其它',
meta: 'Television'
}
]
};
formhash = $('input[name="formhash"]').val();
platform = window.location.href.match(/add_related\/subject\/(anime|book|music|game|real)/)[1];
pagesid = window.location.href.match(/subject\/(\d+)\/add_related/)[1];
submitCue = [];
templates = {};
templates.platforms = (function() {
var i, j, len, platformContent, ref, tpl;
platformContent = '';
tpl = '<label for="platform-{{bgmid}}-{{id}}"><input id="platform-{{bgmid}}-{{id}}" type="radio" value="{{id}}" name="platform-{{bgmid}}"> {{name}}</label>';
ref = platforms[platform];
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
platformContent += tpl.replace(/{{meta}}/g, i.meta).replace(/{{id}}/g, i.id).replace(/{{name}}/g, i.name);
}
return platformContent;
})();
templates.css = "/*-----------------------------------------------------*|*-- Global ------------------------------------------*|\n\*-----------------------------------------------------*/\n#brrs-workspace .hidden {\n display: none; }\n\n#brrs-workspace .chiiBtn.large {\n margin: 5px 2px;\n padding: 5px 10px; }\n\n/*-----------------------------------------------------*|*-- Launcher & Loading -------------------------------*|\n\*-----------------------------------------------------*/\n#brrs-workspace-launcher,\n#brrs-workspace-loading {\n width: 250px;\n margin: 170px auto;\n font-size: 18px;\n text-align: center; }\n #brrs-workspace-loading .brrs-progress {\n margin-top: 3px;\n height: 2px;\n border: none;\n background: #f09199; }\n\n/*-----------------------------------------------------*|*-- Toolkit ------------------------------------------*|\n\*-----------------------------------------------------*/\n#brrs-toolkit {\n width: 100%; }\n #brrs-toolkit .brrs-col-main {\n margin-left: 5%; }\n\n/*-----------------------------------------------------*|*-- Editor -------------------------------------------*|\n\*-----------------------------------------------------*/\n#brrs-subjects-editor {\n width: 100%; }\n #brrs-subjects-editor .renameSubject {\n width: calc(100% - 20px);\n height: 15px; }\n #brrs-subjects-editor .renameSubject {\n width: 40px;\n height: 15px; }\n #brrs-subjects-editor .item {\n height: 40px;\n background: #F9F9F9;\n border-bottom: 1px solid #E0E0E0;\n clear: both;\n padding: 5px 10px; }\n.brrs-editor-item {\n padding: 6px 0 3px 0;\n border-left: 2px solid #369cf8;\n border-bottom: 1px solid #D9D9D9; }\n .brrs-editor-item:hover {\n background: #F4F4F4; }\n [class^=\"brrs-col-\"] {\n line-height: 24px;\n vertical-align: middle;\n overflow: hidden;\n float: left; }\n .brrs-col-close {\n text-align: center;\n font-size: 18px;\n width: 2%; }\n .brrs-col-id {\n text-align: center;\n padding-right: 3px;\n width: calc(3% - 3px); }\n .brrs-col-main {\n width: 60%; }\n .brrs-col-platform {\n width: 23%; }\n .brrs-col-actions {\n width: 12%; }\n\n .brrs-editor-item .details {\n margin-left: 5%; }\n\n #brrs-workspace-editor input,\n #brrs-workspace-editor select {\n vertical-align: middle; }\n #brrs-workspace-editor input.title {\n width: calc(100% - 20px); }\n #brrs-workspace-editor label {\n padding: 0 6px; }\n\n/*-----------------------------------------------------*|*-- Previewer ----------------------------------------*|\n\*-----------------------------------------------------*/\n\n.brrs-col-left,\n.brrs-col-right {\n min-width: calc(50% - 28px);\n width: calc(50% - 28px);\n padding: 0 14px; }\n\n.brrs-previewer-item {\n width: 750px;\n margin: 10px auto;\n border-radius: 10px 10px 0 0;\n box-shadow: 1px 1px 7px rgba(0, 0, 0, .3); }\n .brrs-previewer-item .header {\n background: #F09199;\n color: #FFF;\n padding: 15px 20px 10px;\n border-radius: 10px 10px 0 0; }\n .brrs-previewer-item .header h3 {\n font-size: 18px; }\n .brrs-previewer-item .header h3 small {\n font-size: 10px; }\n .brrs-previewer-item .header h3 a {\n color: #FFF; }\n .brrs-previewer-item .thead .left,\n .brrs-previewer-item .thead .right {\n width: 50%;\n height: 6px;\n float: left;\n text-align: center; }\n .brrs-previewer-item .thead .left {\n background: #31A7DE; }\n .brrs-previewer-item .thead .right {\n background: #56B985; }\n .brrs-previewer-item .content {}\n .brrs-previewer-item .content .title {\n font-size: 18px;\n padding: 0; }\n .brrs-previewer-item .content .title .brrs-col-left,\n .brrs-previewer-item .content .title .brrs-col-right {\n line-height: 35px; }\n .brrs-previewer-item .content .title small {\n color: #555;\n font-size: 12px; }\n .brrs-previewer-item .content .summary {\n overflow: auto;\n overflow-wrap: break-word;\n word-break: break-all; }\n\n#brrs-workspace-previewer .cancel,\n#brrs-workspace-previewer .submit {\n text-align: center; }\n\n/*-----------------------------------------------------*|*-- Footer -------------------------------------------*|\n\*-----------------------------------------------------*/\n#brrs-footer {\n text-align: right;\n color: #999;\n font-size: 12; }";
templates.workspace = (function() {
var platformContent, tpl;
platformContent = templates.platforms.replace(/{{bgmid}}/g, 'master');
return tpl = "<style>\n " + templates.css + "\n</style>\n<div id=\"brrs-workspace\" class=\"columns clearit\" style=\"padding: 10px 0;\">\n <div id=\"brrs-workspace-loading\" class=\"hidden clearit\">\n <p>少女祈祷中……(<span class=\"brrs-var-loaded\"></span>/<span class=\"brrs-var-total\"></span>)</p>\n <div class=\"brrs-progress\"></div>\n </div>\n <div id=\"brrs-workspace-editor\" class=\"hidden clearit\">\n <div id=\"brrs-toolkit\">\n <div class=\"brrs-col-main\">\n <a class=\"chiiBtn\" href=\"#brrs-tool-restore\" data-action=\"restore\">还原所有操作</a>/\n <a class=\"chiiBtn\" href=\"#brrs-tool-removechs\" data-action=\"removechs\">去中文名</a>\n <!-- a class=\"chiiBtn\" href=\"#brrs-tool-removepattern\" data-action=\"removepattern\">批量删除标题指定字符</a -->\n <div id=\"brrs-toolkit-settitle\">\n <label>\n 标题:\n <input type=\"text\" name=\"pattern\" class=\"inputtext\" style=\"width: 40%\" value=\"{{SeriesTitle}} ({{SeriesNumber}})\">\n </label>\n <label>\n 序号起始:\n <input type=\"text\" name=\"seriesstart\" class=\"inputtext\" style=\"width: 20px;\" value=\"1\">\n </label>\n <a class=\"chiiBtn\" href=\"#brrs-tool-settitle\" data-action=\"settitle\">批量替换标题</a>\n <p>{{SeriesTitle}} = 系列标题;{{SeriesNumber}} = 序号</p>\n </div>\n <div id=\"brrs-toolkit-filter\">\n <label>\n 作用范围:\n <input type=\"number\" name=\"start\" class=\"inputtext\" style=\"width: 40px;\" value=\"0\"> ~\n <input type=\"number\" name=\"end\" class=\"inputtext\" style=\"width: 40px;\" value=\"0\">\n </label>\n </div>\n <div id=\"brrs-toolkit-removepattern\" class=\"hidden\">\n <h3>批量删除标题指定字符</h3>\n </div>\n </div>\n\n <div class=\"brrs-col-platform\">\n " + platformContent + "\n </div>\n <div class=\"fixit clearit\"></div>\n </div>\n <div id=\"brrs-subjects-editor\" class=\"clearit\">\n </div>\n <a class=\"chiiBtn large\" id=\"brrs-preview\" href=\"#brrs-preview\">编辑完成,点击预览</a>\n </div>\n <div id=\"brrs-workspace-previewer\" class=\"hidden clearit\">\n <div id=\"brrs-subjects-previewer\" class=\"clearit\">\n </div>\n <div class=\"cancel\">\n <a class=\"chiiBtn large\" id=\"brrs-returneditor\" href=\"#brrs-returneditor\">返回编辑</a>\n </div>\n <div class=\"submit\">\n <label>编辑摘要:<input type=\"text\" name=\"brrs-edit-summary\" class=\"inputtext\" value=\"标题修正+类型修正\"></label>\n <a class=\"chiiBtn large\" id=\"brrs-save\" href=\"#brrs-submit\">确认完毕,点击提交</a>\n </div>\n </div>\n <div id=\"brrs-footer\" class=\"clearit\">\n <p>Powered by BRRS.</p>\n <p>脚本问题反馈/功能请求:<a href=\"/group/topic/311647\" target=\"_blank\">小组讨论帖</a> /\n <a href=\"https://github.com/bangumi/scripts/issues\" target=\"_blank\">GitHub Issues</a>.</p>\n </div>\n</div>";
})();
templates.editor = (function() {
var tpl;
return tpl = "<div class=\"brrs-editor-item clearit\" data-id=\"{{id}}\" data-bgmid=\"{{bgmid}}\">\n <div class=\"brrs-col-close\"><a class=\"brrs-remove\" href=\"#brrs-removeitem\" data-action=\"removeitem\" data-id=\"{{id}}\">×</a></div>\n <div class=\"brrs-col-id\">{{id}}</div>\n <div class=\"brrs-col-main\"><input type=\"text\" class=\"inputtext title\" value=\"{{title}}\" placeholder=\"{{title}}\" name=\"title\" data-id=\"{{id}}\"></div>\n <div class=\"brrs-col-platform\">" + templates.platforms + "</div>\n <div class=\"brrs-col-actions\"><a class=\"chiiBtn\" href=\"#brrs-editor-details\" data-action=\"editdetails\" data-id=\"{{id}}\">编辑详细信息</a></div>\n <div class=\"details clearit hidden\">\n <textarea class=\"quick\" name=\"infobox\" rows=\"15\" style=\"width: 48%\"></textarea>\n <textarea class=\"quick\" name=\"summary\" rows=\"15\" style=\"width: 48%\"></textarea>\n <p><a class=\"chiiBtn large\" href=\"#brrs\" data-action=\"closedetails\" data-id=\"{{id}}\">收起详细信息</a></p>\n </div>\n <div class=\"fixit clearit\"></div>\n</div>";
})();
templates.previewer = "<div class=\"brrs-previewer-item\" data-id=\"{{id}}\" data-bgmid=\"{{bgmid}}\">\n <div class=\"header\"><h3>#<span>{{bgmid}}</span> <small><a href=\"/subject/{{bgmid}}\" target=\"_blank\">在新分页开启</a></small></h3></div>\n <div class=\"thead\">\n <div class=\"left\"></div>\n <div class=\"right\"></div>\n </div>\n <div class=\"content\">\n <div class=\"title clearit\">\n <div class=\"brrs-col-left\">\n {{left.title}} <small> - {{left.platform}}</small>\n </div>\n <div class=\"brrs-col-right\">\n {{right.title}} <small> - {{right.platform}}</small>\n </div>\n </div>\n <div class=\"infobox clearit\">\n <div class=\"brrs-col-left\">\n {{left.infobox}}\n </div>\n <div class=\"brrs-col-right\">\n {{right.infobox}}\n </div>\n </div>\n <div class=\"summary clearit\">\n <div class=\"brrs-col-left\">\n {{left.summary}}\n </div>\n <div class=\"brrs-col-right\">\n {{right.summary}}\n </div>\n </div>\n </div>\n</div>";
Core = {
workspace: function(name) {
$('[id^=brrs-workspace-]').hide();
return $("#brrs-workspace-" + name).show();
},
loading: {
setTotal: function(total) {
return $('.brrs-var-total').html(total);
},
setProgress: function(loaded) {
var prg;
$('.brrs-var-loaded').html(loaded);
prg = (parseInt($('.brrs-var-loaded').text())) / (parseInt($('.brrs-var-total').text()));
$('#brrs-workspace-loading .brrs-progress').stop();
return $('#brrs-workspace-loading .brrs-progress').animate({
width: (prg * 100) + '%'
}, 50);
},
getTotal: function() {
return parseInt($('.brrs-var-total').text());
},
getLoaded: function() {
return parseInt($('.brrs-var-loaded').text());
}
},
toolkit: {
restore: function() {
$('#brrs-subjects-editor input[type="text"], #brrs-subjects-editor textarea').each(function() {
return $(this).val($(this).attr('placeholder'));
});
return $('.brrs-editor-item .brrs-col-platform').each(function() {
return $(this).find("[value=\"" + ($(this).attr('data-origin')) + "\"]").attr('checked', true);
});
},
removechs: function() {
return $('#brrs-subjects-editor textarea[name="infobox"]').each(function() {
var ref;
if (!(((ref = $(this).val().match(/中文名=(.+)/)) != null ? ref[1].trim().length : void 0) > 0)) {
return;
}
return $(this).val($(this).val().replace(/中文名=(.+)/, '中文名= '));
});
},
settitle: function() {
var end, i, pattern, start;
pattern = $('#brrs-toolkit-settitle input[name="pattern"]').val();
i = parseInt($('#brrs-toolkit-settitle input[name="seriesstart"]').val());
if (pattern.match(/{{SeriesTitle}}/) != null) {
pattern = pattern.replace(/{{SeriesTitle}}/g, $('.nameSingle a').text());
}
start = Core.toolkit.filter.getStart();
end = Core.toolkit.filter.getEnd();
return $('#brrs-subjects-editor input.title').each(function() {
var id;
id = parseInt($(this).attr('data-id'));
if (id < start || id > end) {
return;
}
return $(this).val(pattern.replace(/{{SeriesNumber}}/g, i++));
});
},
filter: {
setStart: function(val) {
return $('#brrs-toolkit-filter input[name="start"]').val(parseInt(val));
},
setEnd: function(val) {
return $('#brrs-toolkit-filter input[name="end"]').val(parseInt(val));
},
getStart: function(val) {
return parseInt($('#brrs-toolkit-filter input[name="start"]').val());
},
getEnd: function(val) {
return parseInt($('#brrs-toolkit-filter input[name="end"]').val());
},
refresh: function() {
var end, start;
start = this.getStart();
end = this.getEnd();
return $('.brrs-editor-item').each(function() {
var id;
id = parseInt($(this).attr('data-id'));
if (id < start || id > end) {
return $(this).css({
opacity: 0.4
});
} else {
return $(this).css({
opacity: 1
});
}
});
}
}
},
editor: {
insert: function(id, data) {
var tpl;
tpl = templates.editor;
tpl = tpl.replace(/{{id}}/g, id);
if (data.bgmid != null) {
tpl = tpl.replace(/{{bgmid}}/g, data.bgmid);
}
if (data.title != null) {
tpl = tpl.replace(/{{title}}/g, data.title);
}
return $('#brrs-subjects-editor').append(tpl);
},
remove: function(id) {
return $(".brrs-editor-item[data-id=\"" + id + "\"]").remove();
},
details: {
show: function(id) {
var selector;
selector = ".brrs-editor-item[data-id=\"" + id + "\"] .details";
$(".brrs-editor-item[data-id=\"" + id + "\"] a[data-action=\"editdetails\"]").fadeOut(700);
$(selector).css('height', 0);
$(selector).show();
return $(selector).animate({
'height': '362px'
}, 700, function() {
$(this).css('min-height', '362px');
return $(this).css('height', 'auto');
});
},
hide: function(id) {
var selector;
selector = ".brrs-editor-item[data-id=\"" + id + "\"] .details";
$(selector).css('height', '362px');
$(selector).css('min-height', 0);
$(selector).animate({
'height': 0
}, 700, function() {
return $(selector).hide();
});
return $(".brrs-editor-item[data-id=\"" + id + "\"] a[data-action=\"editdetails\"]").fadeIn(700);
}
},
setPlatform: function(bgmid, platform) {
var origin, selector;
selector = "input[name=\"platform-" + bgmid + "\"][value=\"" + platform + "\"]";
origin = $(selector).parent().attr('data-origin');
$(selector).attr('checked', 'true');
if (origin == null) {
$(selector).parent().parent().attr('data-origin', platform);
}
if (origin == null) {
return $(selector).parent().parent().attr('data-origintext', $(selector).parent().text().trim());
}
},
setInput: function(bgmid, field, text) {
var selector;
selector = ".brrs-editor-item[data-bgmid=\"" + bgmid + "\"] textarea[name=\"" + field + "\"]";
$(selector).val(text);
if (!$(selector).attr('placeholder')) {
return $(selector).attr('placeholder', text);
}
}
},
previewer: {
insert: function(id, bgmid, left, right) {
var tpl;
tpl = templates.previewer;
tpl = tpl.replace(/{{id}}/g, id);
tpl = tpl.replace(/{{bgmid}}/g, bgmid);
tpl = tpl.replace(/{{left.title}}/, left.title);
tpl = tpl.replace(/{{left.platform}}/, left.platform);
tpl = tpl.replace(/{{left.infobox}}/, left.infobox);
if (left.summary.trim() === '') {
tpl = tpl.replace(/{{left.summary}}/, ' ');
} else {
tpl = tpl.replace(/{{left.summary}}/, left.summary.replace(/\n/g, '<br>'));
}
tpl = tpl.replace(/{{right.title}}/, right.title);
tpl = tpl.replace(/{{right.platform}}/, right.platform);
tpl = tpl.replace(/{{right.infobox}}/, right.infobox);
if (right.summary.trim() === '') {
tpl = tpl.replace(/{{right.summary}}/, ' ');
} else {
tpl = tpl.replace(/{{right.summary}}/, right.summary.replace(/\n/g, '<br>'));
}
return $('#brrs-subjects-previewer').append(tpl);
}
}
};
Wcode = {
parse: function(wcode) {
var json, retval;
retval = {};
wcode = wcode.replace(/\r/g, '');
json = wcode.replace(/{{Infobox\s+\w+\/\w+\n([\S\s]*)}}/m, '{\n$1}');
json = json.replace(/\|.+?=\s*\n/g, '');
json = json.replace(/\|(.+?)=\s*{\n*\s*}/, '');
json = json.replace(/\|(.+?)=\s*([^{}]+?)\n/g, ' "$1": "$2",\n');
json = json.replace(/\[(.+?\||)(.+?)\]\n/g, '"$2", ');
json = json.replace(/\|(.+?)=\s*{\n/, ' "$1": [');
json = json.replace(/,\s*}\n/g, ' ],\n');
json = json.replace(/,\s*}/g, '}');
return JSON.parse(json);
},
toHtml: function(json) {
var i, j, key, len, retval, value;
retval = '<ul id="infobox">';
for (key in json) {
value = json[key];
retval += '<li>';
retval += "<span class=\"tip\">" + key + ": </span>";
if (typeof value === 'string') {
retval += value;
} else {
for (j = 0, len = value.length; j < len; j++) {
i = value[j];
retval += '</li>';
retval += "<li class=\"tip\" style=\"visibility:hidden\">.</span> " + i;
}
}
retval += '</li>';
}
return retval += '</ul>';
}
};
$('<a class="chiiBtn rr" id="brrs-launcher-normal" href="#">BRRS</a>').insertAfter('#modifyOrder');
$('<a class="chiiBtn rr" id="brrs-launcher-offprint" href="#">BRRS 单行本</a>').insertAfter('#modifyOrder');
Bootstrap = function(subjects) {
var j, key, len, results, value;
$('#brrs-workspace').remove();
$(templates.workspace).insertBefore('.mainWrapper .columns');
Core.loading.setTotal(subjects.length);
Core.loading.setProgress(0);
Core.workspace('loading');
Core.toolkit.filter.setStart(0);
Core.toolkit.filter.setEnd(subjects.length - 1);
results = [];
for (key = j = 0, len = subjects.length; j < len; key = ++j) {
value = subjects[key];
Core.editor.insert(key, value);
$.ajaxSetup({
async: false
});
results.push($.get("/subject/" + value.bgmid + "/edit_detail", function(data) {
var bgmid;
Core.loading.setProgress(Core.loading.getLoaded() + 1);
bgmid = data.match(/<a href="\/subject\/(\d+)" title="[^"]*" property="v:itemre/)[1];
Core.editor.setInput(bgmid, 'infobox', data.match(/subject_infobox"[^>]+>([\S\s]*?)<\/textarea>/m)[1]);
Core.editor.setInput(bgmid, 'summary', data.match(/subject_summary"[^>]+>([\S\s]*?)<\/textarea>/m)[1]);
Core.editor.setPlatform(bgmid, (data.match(/value="(\d+)" onclick="WikiTpl\('[^']+'\)" checked>/) || ['', ''])[1]);
if (Core.loading.getTotal() === Core.loading.getLoaded()) {
EventBinding();
return $('#brrs-workspace-loading').fadeOut(1000, function() {
return Core.workspace('editor');
});
}
}));
}
return results;
};
$('#brrs-launcher-normal').click(function() {
return Bootstrap((function() {
var retval;
retval = [];
$('#crtRelateSubjects > li').each(function() {
var subject;
subject = {};
subject.bgmid = $(this).attr('item_id');
subject.title = $(this).find('.title a').text().trim();
subject.relation = $(this).find('option[selected="true"]').val();
return retval.push(subject);
});
return retval;
})());
});
$('#brrs-launcher-offprint').click(function() {
return Bootstrap((function() {
var retval;
retval = [];
$('#crtRelateSubjects > li').each(function() {
var subject;
subject = {};
subject.bgmid = $(this).attr('item_id');
subject.title = $(this).find('.title a').text().trim();
subject.relation = $(this).find('option[selected="true"]').val();
if (subject.relation !== '1003') {
return;
}
return retval.push(subject);
});
return retval;
})());
});
EventBinding = function() {
$('a[data-action="removeitem"]').click(function() {
return Core.editor.remove($(this).attr('data-id'));
});
$('a[data-action="editdetails"]').click(function() {
return Core.editor.details.show($(this).attr('data-id'));
});
$('a[data-action="closedetails"]').click(function() {
return Core.editor.details.hide($(this).attr('data-id'));
});
$('#brrs-toolkit a[data-action="restore"]').click(function() {
return Core.toolkit.restore();
});
$('#brrs-toolkit a[data-action="removechs"]').click(function() {
return Core.toolkit.removechs();
});
$('#brrs-toolkit a[data-action="settitle"]').click(function() {
return Core.toolkit.settitle();
});
$('#brrs-toolkit-filter input').bind('input', function() {
return Core.toolkit.filter.refresh();
});
$('#brrs-toolkit input[type="radio"]').click(function() {
var newPlatform;
newPlatform = $(this).val();
return $("#brrs-subjects-editor input[value=\"" + ($(this).val()) + "\"]").attr('checked', true);
});
$('#brrs-preview').click(function() {
var end, start;
$('#brrs-subjects-previewer').html('');
submitCue = [];
start = Core.toolkit.filter.getStart();
end = Core.toolkit.filter.getEnd();
$('.brrs-editor-item').each(function() {
var id, left, right;
id = parseInt($(this).attr('data-id'));
if (id < start || id > end) {
return;
}
right = {
bgmid: $(this).attr('data-bgmid'),
title: $(this).find('input[name="title"]').val().replace(/\r/g, '').trim(),
platform: $(this).find(':checked').parent().text().trim(),
platform_id: $(this).find(':checked').val(),
infobox: $(this).find('textarea[name="infobox"]').val().replace(/\r/g, '').trim(),
summary: $(this).find('textarea[name="summary"]').val().replace(/\r/g, '').trim()
};
left = {
title: $(this).find('input[name="title"]').attr('placeholder').replace(/\r/g, '').trim(),
platform: $(this).find('.brrs-col-platform').attr('data-origintext').trim(),
platform_id: $(this).find('.brrs-col-platform').attr('data-origin'),
infobox: $(this).find('textarea[name="infobox"]').attr('placeholder').replace(/\r/g, '').trim(),
summary: $(this).find('textarea[name="summary"]').attr('placeholder').replace(/\r/g, '').trim()
};
if (left.title === right.title && left.platform === right.platform && left.infobox === right.infobox && left.summary === right.summary) {
return;
}
submitCue.push($.extend({}, right));
left.infobox = Wcode.toHtml(Wcode.parse(left.infobox));
right.infobox = Wcode.toHtml(Wcode.parse(right.infobox));
return Core.previewer.insert($(this).attr('data-id'), $(this).attr('data-bgmid'), left, right);
});
Core.workspace('previewer');
$('html').scrollTop(0);
return null;
});
$('#brrs-save').click(function() {
var editSummary, i, j, len, postData, results;
if (!confirm('这样就好了吗?')) {
return;
}
Core.loading.setTotal(submitCue.length);
Core.loading.setProgress(0);
Core.workspace('loading');
editSummary = $('input[name="brrs-edit-summary"]').val().trim() + ' [BRRS:' + pagesid + ']';
editSummary = editSummary.trim();
$('html').scrollTop(0);
results = [];
for (j = 0, len = submitCue.length; j < len; j++) {
i = submitCue[j];
postData = {};
postData.formhash = formhash;
postData.submit = '提交修改';
postData.editSummary = editSummary;
postData.platform = i.platform_id;
postData.subject_title = i.title;
postData.subject_infobox = i.infobox;
postData.subject_summary = i.summary;
console.log(postData);
$.ajaxSetup({
async: false
});
results.push($.post("/subject/" + i.bgmid + "/new_revision", postData, function() {
Core.loading.setProgress(Core.loading.getLoaded() + 1);
if (Core.loading.getTotal() === Core.loading.getLoaded()) {
return window.location.reload();
}
}));
}
return results;
});
return $('#brrs-returneditor').click(function() {
return Core.workspace('editor');
});
};