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.

Prefix for topic titles

5 posters

Go down

Solved Prefix for topic titles

Post by Guest January 24th 2023, 3:00 pm

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 January 24th 2023, 6:56 pm; edited 1 time in total
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix for topic titles

Post by Guest January 24th 2023, 5:21 pm

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


Back to top Go down

Solved Re: Prefix for topic titles

Post by Ape January 24th 2023, 5:35 pm

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
Ape
Ape
Administrator
Administrator

Male Posts : 19432
Reputation : 2010
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Solved Re: Prefix for topic titles

Post by Razor12345 January 24th 2023, 5:44 pm

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
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1581
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Prefix for topic titles

Post by Guest January 24th 2023, 6:14 pm

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


Back to top Go down

Solved Re: Prefix for topic titles

Post by Guest January 24th 2023, 6:31 pm

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
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix for topic titles

Post by zest_n January 24th 2023, 6:46 pm

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] */
avatar
zest_n
New Member

Posts : 17
Reputation : 7
Language : English

TonnyKamper likes this post

Back to top Go down

Solved Re: Prefix for topic titles

Post by skouliki January 24th 2023, 6:49 pm

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

Female Posts : 15391
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Prefix for topic titles

Post by SLGray January 25th 2023, 2:19 am

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.
SLGray
SLGray
Administrator
Administrator

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

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum