Skip to content

Block Domain

Solved Let's Build It
  • @DownPW said in Block Domain:

    If you have any ideas for adapting it to quick reply and composing. I’m interested.

    Let me have a look at this in more detail in DEV.

  • In previous code, i want to add html link to rules page like this :

    html = html.replace(/https?:\/\/(www\.)?francesoir\.fr[^\s]*/g, '<a href="https://XXXXX.XXXXX.XXX/rules">Test</a>');
    

    But i have this on result :

    image.png

    an idea ?

  • @DownPW Yes, direct HTML rendering is disabled (as is JS) in the composer so it will be stripped. For this to work, you’d need to enable HTML support in the composer which isn’t recommended for security reasons.

  • too bad I would have liked to be redirected to the necessary page

    ChatGPT doesn’t help on this 😉

  • I have a great code here. I managed to modify the HTTP URL link as well as the link text (description) by modifying them both with a warning message and the URL of my choice for each domain. I am currently redirecting to my checkout page.

    The code also differentiates with text before and after the link and does not take it into account.

    It works :

    • In the topics
    • In the carousel
    • In the previews of the last post in the recent page, unread etc…
    • In Chat

    There are certainly things to improve but I’ll share the code with you here.

    –> This will be my Christmas present 🎅

    If you have any improvements or suggestions, don’t hesitate @phenomlab

    // ------------------------------------------------------------------
    // Block Domain URL on topics & Topic teasers & caroussel topic info
    // ------------------------------------------------------------------
    
    $(document).ready(function () {
      // Function to replace URLs and link text in a given HTML content
      function replaceUrls(html) {
        // Replace the old domain URLs with the new domain URL and update link text
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?francesoir\.fr(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a disinformation domain name] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?francais\.rt\.com(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a domain name of disinformation and propaganda] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?fr\.sputniknews\.africa(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a domain name of disinformation and propaganda] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?lecourrierdesstrateges\.fr(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a disinformation domain name] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?lelibrepenseur\.org(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a disinformation domain name] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?lesmoutonsenrages\.fr(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The anti fake news system detected a domain name spreading hate speech and anti-Semitic comments] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?upr\.fr(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a disinformation domain name] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?lecourrier-du-soir\.com(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The PW anti fake news system detected a disinformation domain name] 🤖</strong></a>');
        html = html.replace(/(<a[^>]*href="https?:\/\/(?:www\.)?fdesouche\.com(?:\/[^\s>]*)?"[^>]*>)([^<]*)<\/a>/g, '<a href="https://YOUR_URL_REDIRECTION/rules"><strong>🤖 [Oups. The anti-fake news system detected a domain name disseminating racist hate articles] 🤖</strong></a>');
        // Add more lines for additional domains if needed
        return html;
      }
    
      // Function to replace URLs and link text in a given content element
      function replaceUrlsInContent($content) {
        $content.html(function (_, oldHtml) {
          return replaceUrls(oldHtml);
        });
      }
    
      // Replace URLs and link text when a new post is added
      $(window).on('action:posts.loaded', function () {
        $('[component="post"]').each(function () {
          var $postContent = $(this).find('.content, .topic-info.text-sm.text-break, .content.mt-2.text-break, .stretched-link, .message-body.ps-0.py-0.overflow-auto.text-break');
          // Replace URLs and link text in the post content
          $postContent.html(replaceUrls($postContent.html()));
        });
      });
    
      // Replace URLs and link text when a post is edited
      $(window).on('action:topic.loaded', function () {
        $('[component="post"]').each(function () {
          var $postContent = $(this).find('.content, .topic-info.text-sm.text-break, .content.mt-2.text-break, .stretched-link, .message-body.ps-0.py-0.overflow-auto.text-break');
          // Replace URLs and link text in the post content
          $postContent.html(replaceUrls($postContent.html()));
        });
      });
    
      // Replace URLs and link text when a new page is loaded or content is updated for topic teaser & carroussel topic info
      $(document).ajaxComplete(function () {
        $('.post-content.text-xs.ps-2.line-clamp-sm-2.lh-sm.text-break, .topic-info.text-sm.text-break, .content.mt-2.text-break, .stretched-link, .message-body.ps-0.py-0.overflow-auto.text-break').each(function () {
          var $content = $(this);
          replaceUrlsInContent($content);
        });
      });
    });
    

    PS : nothing to see but appearance code on topics bug :
    The Block code is no longer displayed in its entirety but only on one line :

    f28171b1-e396-49dc-a8f3-97be40f04371-image.png

  • DownPWundefined DownPW has marked this topic as solved on
  • @DownPW that code looks great. I seem to have trained you well!

    I’ll investigate the single line of code issue. I think that’s probably because of a modified version of highlight. js I use.

  • @phenomlab

    My code work great but a little more 😉
    My code conflicts with your OGPROXY code.

    Do you have an idea so that the two can live together?

  • @DownPW Potentially, yes, but what is the conflict exactly?

  • I don’t know, I just see that OG proxy does not format the links when my code to block domains is active.

    If I disable it, OG proxy works fine.

    I would have to make sure that OG proxy does not activate when a blacklist link is detected or that it works one after the other

    Actually I don’t really know at the moment.

    EDIT:

    Maybe add an ignore list to OG PROXY

  • @DownPW said in Block Domain:

    I don’t know, I just see that OG proxy does not format the links when my code to block domains is active.

    This just means that the callback / hook isn’t monitored by OGProxy and can probably be quite easily rectified.

    @DownPW said in Block Domain:

    Maybe add an ignore list to OG PROXY

    There is one already in function.js - see below

    https://github.com/phenomlab/ogproxy/blob/03d5ff125611361700d785bd82a6ab16fcd68bfc/function.js#L9

  • In any case, it doesn’t change anything in fact I think to add exclusions in OG Proxy, because links which are not to be ignored are not formatted by OG proxy

    @phenomlab said in Block Domain:

    This just means that the callback / hook isn’t monitored by OGProxy and can probably be quite easily rectified.

    I’ll look and try to figure it out but can you help me with this ?

  • @DownPW said in Block Domain:

    I’ll look and try to figure it out but can you help me with this ?

    Yes, of course.

  • no luck for now

  • @DownPW Can you provide a summary of what you’ve tried?

  • I don’t have everything listed.

    In fact I’m trying to understand what’s going on, otherwise I’m going all over the place but I don’t have any errors in the console.

    In fact I have the impression that the 2 codes act on <a> and that they sometimes come into conflict because when I enter the topic via the recent page or other, OG proxy does the job, I refresh, it works again , I refresh and the OGproxy does nothing.

    I have the impression that both codes are playing with the DOM and it’s not okay.
    Sometimes OGproxy works, sometimes it works on every second link, and sometimes not at all.

    Anyway, I’m a little lost at the moment.

    I don’t really know what changed or what script changed.

  • @DownPW I don’t think this is OGProxy. I think it’s your script that manipulates the DOM afterwards and causes the issue. Is there somewhere I can see the script and review it (dev) ?

  • Script is on dev yes.

  • @DownPW is OGProxy also on dev? I’ll need both running

  • Yes ogproxy too is functionnal on dev


Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation 💗

  • Page control arrows for PWA

    Solved Customisation
    27
    25 Votes
    27 Posts
    400 Views

    @crazycells it is, yes - I think I’ll leave it as there is no specific PWA CSS classes I know of. Well, you could use something like the below, but this means multiple CSS files for different operating systems.

    /** * Determine the mobile operating system. * This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'. * * @returns {String} */ function getMobileOperatingSystem() { var userAgent = navigator.userAgent || navigator.vendor || window.opera; // Windows Phone must come first because its UA also contains "Android" if (/windows phone/i.test(userAgent)) { return "Windows Phone"; } if (/android/i.test(userAgent)) { return "Android"; } if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return "iOS"; } return "unknown"; // return “Android” - one should either handle the unknown or fallback to a specific platform, let’s say Android }

    Once you’re in that rabbit hole, it’s impossible to get out of it.

  • Whitespace fixes in Nodebb

    Solved Customisation
    18
    7 Votes
    18 Posts
    777 Views

    @Panda Just circling back here with something of an update (which I think you’ll like). I’ve completely restructured the ranking system. There are now less ranks, with a higher point threshold to reach them.

    More importantly, if you reload the site, you’ll notice that the ranks are now icons.

    I also removed the “Author” badge, and made this a single icon, which (to me) looks much better.

  • 2 Votes
    26 Posts
    1k Views

    @Panda said in Interesting Widget code, but can’t fetch API:

    How did you drop that widget into the post there?
    I hadnt seen this BSgenerator anywhere on sudonix site, do you use it somewhere already?

    Yes, here

    https://sudonix.org/topic/414/corporate-bullshit-generator?_=1687774393044

    It’s not a “post” or “topic” in the common sense. It is actually a page in it’s own right and leverages nodebb-plugin-custom-pages. This in turn creates a new “route” which behaves like a page, meaning it is then exposed for widgets.

    @Panda said in Interesting Widget code, but can’t fetch API:

    Also can you explain more what you mean by calling the code externally. In my API call example, how would I go about doing that?

    By this, I mean create all the required code in an external JS file that is reachable by the NodeBB instance - so, in “public” for example - or in my case /public/js. The widget then “calls” that file and because it runs outside of the scope of NodeBB, you just need to return the values to the widget.

    Hope this makes sense?

  • NodeBB upgrade now cant post

    Solved Bugs
    5
    2 Votes
    5 Posts
    182 Views

    @Panda yes, for some reason, that is the case. If you need an urgent response, it’s probably better to post here because of the time difference.

  • 2 Votes
    19 Posts
    579 Views

    @phenomlab Work now 😉

  • 3 Votes
    9 Posts
    413 Views

    The real issue here is that most people consider forums to be “dead” in the sense that nobody uses them anymore, and social media groups have taken their place. Their once dominant stance in the 90’s and early 00’s will never be experienced again, but having said that, there are a number of forums that did in fact survive the social media onslaught, and still enjoy a large user base.

    Forums tend to be niche. One that immediately sticks out is Reddit - despite looking like it was designed in the 80s, it still has an enormous user base. Another is Stack Overflow, which needs no introduction. The key to any forum is the content it offers, and the more people whom contribute in terms of posting , the more popular and widely respected it becomes as a reliable source of information.

    Forums are still intensely popular with gamers, alongside those that offer tips on hacking etc.

  • 4 Votes
    8 Posts
    2k Views

    @DownPW done

  • Nodebb Hashtag plugin

    Solved General
    15
    1 Votes
    15 Posts
    726 Views

    @jac Great ! I’ll close this off.