Search found 2 matches for prefix

[Userscript] Sửa tiền tố cho bài viết

Diễn đàn: UserscriptTrả lời: 5Lượt xem: 2355

 31.01.15 10:44

Userscript này dùng cho Mod của diễn đàn, giúp sửa tiền tố cho bài viết trong Thùng rác ở Devs forumvi.

Devs forumvi, mình thiết lập tiền tố riêng cho từng mục, trong đó tiền tố [Thùng rác] có tác dụng là kéo những bài đó xuống cuối bảng thống kê bài mới.
Khi quăng bài vào Thùng rác thì nó vẫn còn nguyên tiền tố chuyên mục cũ, vì vậy phải sửa nó về tiền tố [Thùng rác], userscript này là để giúp Mod làm việc đó nhẹ nhàng hơn.

Nếu diễn đàn khác có nhu cầu tương tự, cần dùng thì sửa Selector và liên kết ở @include cho phù hợp.


Cài đặt


https://openuserjs.org/scripts/baivong/S%E1%BB%ADa_ti%E1%BB%81n_t%E1%BB%91_cho_b%C3%A0i_vi%E1%BA%BFt
https://github.com/baivong/Userscript/blob/master/Forumotion/editPrefix.user.js

Mã nguồn


Code:
// ==UserScript==
// @name        Sửa tiền tố cho bài viết
// @namespace  zzbaivong
// @description Nhấn [Sửa tiền tố] ở những bài chưa đổi tiền tố trong Thùng rác
// @include    http://devs.forumvi.com/f24-*
// @include    http://devs.forumvi.com/f24p*
// @version    1.0.1
// @grant      none
// ==/UserScript==

$(function () {
    $('.prefix').show();
    $('.stat4r a[href^=\'/t\']a[href*=\'#\']').attr('href', function () {
        return '/post?p=' + this.href.split('#') [1] + '&mode=editpost'
    }).text('[ Sửa tiền tố ]').css('float', 'right').click(function (d) {
        d.preventDefault();
        var b = this;
        $.post(b.href, function (a) {
            a = $(a);
            var c = '[' + $('.nav[href^=\'/f\']:last').text() + '] ' + $.trim(a.find('#modif_topic_title').val().replace(/\[([^\[\]])+\]/g, ''));
            $.post(b.href, {
                subject: c,
                modif_topic_title: c,
                message: a.find('#text_editor_textarea').val(),
                post: 'Send'
            }, function (a) {
                $(b).closest('tr').fadeOut(300)
            });
        })
    })
});



Zzbaivong (devs.forumvi.com)
Tags: #google-chrome #firefox #userscript #prefix

 26.07.14 0:04

Cập nhật mod Topic prefixes cũ của Việt K. Mod này sẽ tạo ra một danh mục các tiền tố (prefix) cho người dùng lựa chọn khi họ đăng bài viết.

Topics tagged under prefix on DEVs forumvi 3GS5LhP

Thay code prefix của ViệtK bằng code này:
Code:
var prefixes = ["Thông báo", "Tài liệu", "Bàn luận", "Chia sẻ", "Giải trí", "Truyện", "Tin tức", "Video - Clip", "Âm nhạc", "Bầu chọn", "Kiến thức", "Kĩ năng", "Tranh luận"]; //danh sách các prefix
var _pm = false; //true: cho phép dùng prefix khi gửi tin nhắn
/*!
 * Topic prefixes - Copyright © 2011 by Viet K - chinhphuc.info
 * Fix by Zzbaivong - devs.forumvi.com
 */
$(function() {
    var chk = false;
    if (_pm) chk = /\privmsg/.test(location.href);
    if (/\/post/.test(location.href) || chk) {
        var $select = $("<select>", {
            id: "prefix",
            style: "margin-top: 2px; margin-right:5px; height: 21px",
            size: 1,
            html: '<option value="">(Chọn tiền tố)</option>'
        });
        $.each(prefixes, function(i, val) {
            $("<option>", {
                value: val,
                text: val
            }).appendTo($select);
        });
        var $subject = $("input[name='subject']");
        $select.insertBefore("input[name='subject']");
        $subject.width($subject.width() - $select.width() - 5);
        var testPrefix = new RegExp("^\\[(" + prefixes.join("|") + ")\\]");
        var title = $subject.val();
        if (testPrefix.test(title)) {
            var prefix = title.match(/^\[([^\[\]]+)\]\s*(.*)/);
            $select.find("option[value='" + prefix[1] + "']").attr("selected", true);
            console.log($select.find("option[value='" + prefix[1] + "']"));
            $subject.val(prefix[2]);
        }
        $("input[name='post']").click(function() {
            if ($subject.val().trim() !== "" && $select.val() !== "") $subject.val("[" + $select.val() + "] " + $subject.val())
        });
    }
});

Tags: #mod #javascript #jquery #prefix


Back to top