Created
February 10, 2018 16:45
-
-
Save UniIsland/2a65400f4f025ca023d722ff6459b0a3 to your computer and use it in GitHub Desktop.
Tampermonkey Script for 知乎话题快捷绑定(知乎问答页改版后已不再可用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name zhihu - 快捷话题绑定 | |
// @namespace http://www.zhihu.com/ | |
// @version 0.1 | |
// @description enter something useful | |
// @match http://www.zhihu.com/question/* | |
// @copyright 2012+, You | |
// ==/UserScript== | |
var topics = [[220,'知乎社区'],[33917,'个人咨询'],[87436,'成人内容'],[1309,'调查类问题']]; | |
var style_string = '.zm-tag-editor-shortcut-btn.zm-item-tag {float:none;cursor:pointer;color:#259;}'; | |
$('<style/>').html(style_string).appendTo('head'); | |
var bind_url = '/topic/bind'; | |
var $topic_edit_btn = $('.zm-tag-editor .zm-tag-editor-labels .zu-edit-button'); | |
var q_id = $('#zh-question-detail').data('resourceid'); | |
var xsrf = $('input[name="_xsrf"]').val(); | |
$topic_edit_btn.live('click', function() { | |
console.log('captured'); | |
if ($('.zm-tag-editor-shortcut')[0]) return; | |
var $topic_edit_box = $('<div />').addClass('zm-tag-editor-shortcut') | |
.insertAfter('.zm-tag-editor-command-buttons-wrap'); | |
for (var i = 0; i < topics.length; i++) { | |
$('<div />').addClass('zm-tag-editor-shortcut-btn').addClass('zm-item-tag') | |
.text(topics[i][1]) | |
.attr('_tid',topics[i][0]) | |
.appendTo($topic_edit_box); | |
} | |
}); | |
$('.zm-tag-editor-shortcut-btn.zm-item-tag').live('click', function(event) { | |
var t_id = $(this).attr('_tid'); | |
$.ajax({ | |
url: bind_url, | |
type: 'POST', | |
data: { | |
qid: q_id, | |
question_id: q_id, | |
topic_id: t_id, | |
_xsrf: xsrf | |
}, | |
dataType: 'json', | |
success: function(data) { | |
if (!data[0]) { alert('綁定失敗'); } | |
var $topic_edit_btn = $('.zm-tag-editor .zm-tag-editor-labels .zu-edit-button'); | |
var $topic_edit_list = $('.zm-tag-editor-editor .zg-section').first(); | |
$('<a />').addClass('zm-item-tag').attr('href','#').text(data[0]) | |
.insertBefore($topic_edit_btn); | |
var $span = $('<span />').addClass('zm-tag-editor-edit-item'); | |
$('<a />').addClass('nor').attr('href','#').text(data[0]) | |
.appendTo($span); | |
$span.appendTo($topic_edit_list); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment