The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
5 posters

    Prefix for topic titles

    avatar
    Guest
    Guest


    Solved Prefix for topic titles

    Post by Guest 24/1/2023, 21:00

    Forum version: ModernBB

    I am trying to find a script where I can add prefixes for topic titles, something like: Tutorial, News.. Now, I tried many scripts I found here and none seemed to work for me.
    When I say prefix, I don't only mean text [NEWS], I want that to be converted into something with different background color and text color. When user checkout topic titles, there will be prefix + topic title.

    So, how can that be done?
    Big plus would be if there is a tutorial to do that while creating topic (drop-down menu) without need to type [NEWS] manually.
    Thanks.


    Last edited by System32 on 25/1/2023, 00:56; edited 1 time in total
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15311
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    Solved Re: Prefix for topic titles

    Post by skouliki 24/1/2023, 21:13


    avatar
    Guest
    Guest


    Solved Re: Prefix for topic titles

    Post by Guest 24/1/2023, 23:21

    Last link doesn't support ModernBB.
    Second link again, not for ModernBB.
    Tested first link, doesn't work. Nothing shows up.
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19325
    Reputation : 2005
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: Prefix for topic titles

    Post by Ape 24/1/2023, 23:35

    Sadly this was never made to work with ModernBB forums as they was made a long time ago.
    With basic CSS and javascript knowledge I'm sure you can make it work for your forum as well.



    Prefix for topic titles Left1212Prefix for topic titles Center11Prefix for topic titles Right112
    Prefix for topic titles Ape_b110
    Prefix for topic titles Ape1010
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

    Solved Re: Prefix for topic titles

    Post by Razor12345 24/1/2023, 23:44

    Based on this tutorial.

    JQuery Code:

    Code:
    $(function() {
        var c = document.querySelectorAll('.post h2.topic-title a');
        for (i=0; i<c.length; i++) {   
          c[i].innerHTML = c[i].innerHTML.replace(/#TEXT/g,'<span id="TEXT">TEXT</span>');
        }
    });

    CSS unchanged

    Result:

    Prefix for topic titles Screen10



    Prefix for topic titles Screen51
    avatar
    Guest
    Guest


    Solved Re: Prefix for topic titles

    Post by Guest 25/1/2023, 00:14

    Yes, it does work inside the topic, but I was refering to topic list. I edited this in console, but that's the final result I am looking for:

    Prefix for topic titles Scree176
    avatar
    Guest
    Guest


    Solved Re: Prefix for topic titles

    Post by Guest 25/1/2023, 00:31

    Ok, I found a solution. I made my own script, something like this:

    Code:
    // [NEWS] .news
    // [TUTORIAL] .tutorial
    // [ARTICLE] .article
    // []
    $(document).ready(function() {
      var titleDiv = $("a.topictitle");
     
      titleDiv.each(function() {
        var title = $(this).html();
        console.log(title);
       
        if(title.includes("[NEWS]")) {
        $(this).html($(this).html().replace('[NEWS]', '<span class="news">NEWS</span>'))
        }     
     
      });
     
    });

    Applied in sub-forum. I was just lazy to write this, hopped there is already done. Sad
    zest_n
    zest_n
    New Member


    Posts : 14
    Reputation : 5
    Language : English

    Solved Re: Prefix for topic titles

    Post by zest_n 25/1/2023, 00:46

    hello, you can try this code
    Placement: In all the pages
    Code:
    var prefixes = ["In progcess", "Solved", "Test", "fm codes"]; //your prefixes
    var _pm = false; //true: allowed prefixes in pm
    var chk = false;
    function toMenu(a) {
      var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
      for (i in a)
      htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
      htmlpre += '</select>';
      return htmlpre;
    }

    function checkpre(ar, input) {
      for (i in ar) {
          var p = new RegExp("\\" + ar[i], "g");
          var title = input.substr(0, input.indexOf(']'));
          if (p.test(title)) return ar[i];
      }
      return "";
    }
    $(function () {
      if (_pm) chk = /\privmsg/.test(location.href);
      if (/\/post/.test(location.href) || chk) {
          $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
          var mw = $("#prefix").width() + 5;
          $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
          var t = $("[name='subject']").val();
          var cur = checkpre(prefixes, t);
          if (cur != "") {
            $("[value=" + cur + "]").attr("selected", "selected");
            $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
          }
          $("input[name='post']").click(function () {
            var sub = $("input[name='subject']").val().trim();
            if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
          })
      }
    });

    $(function () {
      $("a[href^='/t'], a[href^='http://" + location.host + "/t']").html(function () {
          var a = $(this).text();
          if(/^\[([^\[\]]+)\]/.test(a)) return a.replace(/^\[[^\[\]]+\]/, function (a) {
            return '<span class="prefix ' + a + '">' + a.slice(1,-1) + "</span>"
          })
      });
    });

    CSS
    Code:
    .prefix{background:#008287;color:#FFF;border-radius:2px;display:inline-block;height:18px;line-height:18px;padding:0 4px} /*default style*/
    .prefix.\[Solved\]{background:#16499a} /* style for prefix [Solved] */
    .prefix.\[Test\]{background:#60a917} /*style for prefix [Test]*/
    .prefix.\[fm.codes\]{background:#fa6800} /*style for prefix [fm codes] */
    .prefix.\[In.progress\]{background:red} /*style for prefix [In progress] */

    TonnyKamper likes this post

    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15311
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    Solved Re: Prefix for topic titles

    Post by skouliki 25/1/2023, 00:49

    When your request is complete, please mark it as Solved.

    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51498
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Prefix for topic titles

    Post by SLGray 25/1/2023, 08:19

    Problem solved & topic archived.
    Please read our forum rules:  ESF General Rules



    Prefix for topic titles Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.

      Current date/time is 23/9/2024, 02:24