javascript – Hide link formatting Firefox extension

I’m building a Mozilla Firefox extension to hide link’s formatting and show them as regular text. It consists of a script that runs on web-pages (content.js) that’s activated by clicking on the extension (handled with background.js). On activation, a CSS rule is injected to hide link’s formatting. Activating it again will shut changes off.

background.js additionally updates the extension’s icon (based on links being currently hidden or not) every time the active tab is changed.

I’m new to JavaScript. I’d really appreciate your comments and observations to improve it (best practices, code structure, etc).

Script that runs on web pages (content.js):

'use strict';

// Links formatting state variable
let hideLinks = false;
const hideLinksRule = `
a,
a:hover,
a:focus,
a:active,
a:visited {
    text-decoration: none !important;
    color: inherit !important;
    background-color: inherit !important;
    border-bottom: initial !important;
}`;


let styleSheet = (function () {
    let style = document.createElement('style');
    document.head.appendChild(style);
    return style.sheet;
})();


function handleRequest(request) {
    
    // Do not modify if request is only a query
    if (request.isQuery) {
        return Promise.resolve({
            hideLinks
        });
    }

    // Toggle hide/show link formatting
    if (hideLinks) {
        styleSheet.deleteRule(0);
        hideLinks = !hideLinks;
    } else {
        styleSheet.insertRule(hideLinksRule, 0);
        hideLinks = !hideLinks;
    }

    // Return links state
    return Promise.resolve({
        hideLinks
    });

}


browser.runtime.onMessage.addListener(handleRequest);

Script to handle the extension on the browser (background.js):

// Icons paths
const showLinksIconPath = {
    path: 'icons/link-icon.png'
};
const hideLinksIconPath = {
    path: 'icons/broken-link-icon.png'
};


function onError(error) {
    browser.browserAction.setIcon(showLinksIconPath);
}


function updateIcon(response) {
    if (response.hideLinks) {
        browser.browserAction.setIcon(hideLinksIconPath);
    } else {
        browser.browserAction.setIcon(showLinksIconPath);
    }
}


function verifyTabStatus(activeInfo) {
    browser.tabs.sendMessage(
        activeInfo.tabId, {
            isQuery: true
        }
    ).then(updateIcon).catch(onError);
}


function activeTabLinkToggle() {
    browser.tabs.query({
        currentWindow: true,
        active: true
    }).then(requestLinkFormatToggle).catch(onError);                
}


function requestLinkFormatToggle(tabs) {
    
    if (!(tabs === undefined || tabs.length == 0)) {
        const activeTab = tabs(0);
        browser.tabs.sendMessage(
            activeTab.id, {
                isQuery: false
            }
        ).then(updateIcon).catch(onError);
    }

}


// Update Icon on tab change
browser.tabs.onActivated.addListener(verifyTabStatus);


// Request toggle link formatting on click
browser.browserAction.onClicked.addListener(activeTabLinkToggle);

Configuration file to put it together (manifest.json):

{

    "manifest_version": 2,
    "name": "No-link",
    "version": "1.0",

    "description": "Hide link formatting.",

    "icons": {
        "48": "icons/link-icon.png"
    },


    "permissions": (
        "tabs"
    ),


    "browser_action": {
        "default_icon": "icons/link-icon.png",
        "default_title": "No-link"
    },


    "background": {
        "scripts": ("background.js")
    },
    
    "content_scripts": (
        {
            "matches": ("<all_urls>"),
            "js": ("content.js")
        }
    )

}

You can also get the source code here.
Thank you very much for your time.

customization – Unable to view icons (mobile view etc) next to “Hide Controls” in admin customize.php

I have installed wordpress 5.3.2 on my localhost and everything was fine for 1 month. suddenly the Mobile view and Desktop view icons are missing from
http://localhost/WordPress/wp-admin/customize.php
I have disabled all the plugins and deleted unused themes but still no use.

I have updated the wordpress to 5.5.1, but the issue remains there. The other details are:

mysql Ver 15.1 Distrib 10.4.14-MariaDB, for Win64 (AMD64), source revision ddffcad64c9ff3299037eed9df1bc92d51f8d07e

nisar@RAMAKRISHNA c:xampp

Server version: Apache/2.4.46 (Win64)
Apache Lounge VC15 Server built: Aug 4 2020 11:50:23

nisar@RAMAKRISHNA c:xampp

PHP 7.4.9 (cli) (built: Aug 4 2020 11:52:41) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

javascript – UI & Global Controller to hide `div` element based on `selected` option?

I have the following HTML + JavaScript code:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<div class="container mt-4">

  

<!-- action="/reports_send/21-TEMP-01a" method="POST" -->
    <h3>Form:</h3>
    <form id="form" class="mt-4 mb-4" >

        <div style="border: 1px solid black; padding: 40px; border-radius: 25px;">
            <div class="container mt-4">
                <div id="errors" class="mt-4"></div>
            </div>

            <h4>Select Room</h4>
            <div id="RoomSelect">
                <select id="RoomMenu" class="form-control mb-4"> 
                    <!-- Drying Room 1 -->
                    <option value="dry-1">Drying Room 1</option>
                    <!-- Drying Room 2 -->
                    <option value="dry-2">Drying Room 2</option>
                    <!-- Dry Store-->
                    <option value="dry-3">Dry Store</option>
                </select>
            </div>
            
            <div id="RoomInputs">

                <!-- Drying Room 1 -->
                <div class="form-group" id="dry-1">
                    <!-- Title -->
                    <h4>Drying Room 1</h4>

                    <!-- All temperatures -->
                    <div class="temperatures">
                        <!-- Actual Temperature -->
                        <label>Temperature °C - <strong>Actual</strong></label>
                        <input type="number" class="form-control" name="actual-temp-1">

                        <!-- Minimum Temperature -->
                        <label>Temperature °C - <strong>Minimum</strong></label>
                        <input type="number" class="form-control" name="min-temp-1">

                        <!-- Maximum Temperature -->
                        <label>Temperature °C - <strong>Maximum</strong></label>
                        <input type="number" class="form-control" name="max-temp-1">
                    </div>
                    <br>
                    <br>
                    <!-- All humidity -->
                    <div class="humidity">
                         <!-- Actual Humidity -->
                        <label>Relative Humidity - <strong>Actual</strong></label>
                        <input type="number" class="form-control" name="actual-temp-2">
                         <!-- Minimum Humidity -->
                        <label>Relative Humidity - <strong>Minimum</strong></label>
                        <input type="number" class="form-control" name="min-temp-2">
                         <!-- Maximum Humidity -->
                        <label>Relative Humidity - <strong>Maximum</strong></label>
                        <input type="number" class="form-control" name="max-temp-2">
                    </div>
                </div>


                <!-- Drying Room 2 -->
                <div class="form-group" id="dry-2">
                    <!-- Title -->
                    <h4>Drying Room 2</h4>

                    <!-- All temperatures -->
                    <div class="temperatures">
                        <!-- Actual Temperature -->
                        <label>Temperature °C - <strong>Actual</strong></label>
                        <input type="number" class="form-control" name="actual-temp-3">

                        <!-- Minimum Temperature -->
                        <label>Temperature °C - <strong>Minimum</strong></label>
                        <input type="number" class="form-control" name="min-temp-3">

                        <!-- Maximum Temperature -->
                        <label>Temperature °C - <strong>Maximum</strong></label>
                        <input type="number" class="form-control" name="max-temp-3">
                    </div>
                    <br>
                    <br>
                    <!-- All humidity -->
                    <div class="humidity">
                         <!-- Actual Humidity -->
                        <label>Relative Humidity - <strong>Actual</strong></label>
                        <input type="number" class="form-control">
                         <!-- Minimum Humidity -->
                        <label>Relative Humidity - <strong>Minimum</strong></label>
                        <input type="number" class="form-control">
                         <!-- Maximum Humidity -->
                        <label>Relative Humidity - <strong>Maximum</strong></label>
                        <input type="number" class="form-control">
                    </div>
                </div>

                <!-- Dry Store -->
                <div class="form-group" id="dry-3">
                    <!-- Title -->
                    <h4>Dry Store</h4>

                    <!-- All temperatures -->
                    <div class="temperatures">
                        <!-- Actual Temperature -->
                        <label>Temperature °C - <strong>Actual</strong></label>
                        <input type="number" class="form-control">

                        <!-- Minimum Temperature -->
                        <label>Temperature °C - <strong>Minimum</strong></label>
                        <input type="number" class="form-control">

                        <!-- Maximum Temperature -->
                        <label>Temperature °C - <strong>Maximum</strong></label>
                        <input type="number" class="form-control">
                    </div>
                    <br>
                    <br>
                    <!-- All humidity -->
                    <div class="humidity">
                         <!-- Actual Humidity -->
                        <label>Relative Humidity - <strong>Actual</strong></label>
                        <input type="number" class="form-control">
                         <!-- Minimum Humidity -->
                        <label>Relative Humidity - <strong>Minimum</strong></label>
                        <input type="number" class="form-control">
                         <!-- Maximum Humidity -->
                        <label>Relative Humidity - <strong>Maximum</strong></label>
                        <input type="number" class="form-control">
                    </div>
                </div>

            </div>
            
        </div>
    </form>

</div>
<button id="submit-btn" class="btn btn-primary">Submit</button>

<script>

// UI CONTROLLER
var UIController = (() => {

// Store DOM Strings
var DOMStrings = {
    room_options: '#RoomMenu',
    btn: '#submit-btn'
};



return {

    // Hide all Div Elements

    hideDivElements: () => {
        console.log(document.querySelector(DOMStrings.room_options).value);

        for(const option of document.querySelector(DOMStrings.room_options).options) {
            document.querySelector(`#${option.value}`).style.display = "none";
        }

        if(document.querySelector(DOMStrings.room_options).value === 'dry-1') {
            document.querySelector('#dry-1').style.display = "block";
        } else if (document.querySelector(DOMStrings.room_options).value === 'dry-2') {
            document.querySelector('#dry-2').style.display = "block";
        } else if (document.querySelector(DOMStrings.room_options).value === 'dry-3') {
            document.querySelector('#dry-3').style.display = "block";
        }
    },



    // Return DOM Strings
    getDOMStrings: () => {
        return DOMStrings;
    }
}



})();


// GLOBAL APP CONTROLLER
var controller = ((UICtrl) => {

    var setupEvenetListeners = () => {

        // Get dom strings from UI Controller
        var DOM = UICtrl.getDOMStrings();

        // On change
        document.querySelector(DOM.room_options).addEventListener('change', () => {
            UICtrl.hideDivElements();
        });

        

    }

    return {
        init: () => {
            console.log("Application has started");
            UICtrl.hideDivElements(); // Hide elements at start of program
            setupEvenetListeners();


        }
    }

})(UIController);

controller.init();

</script>

Question

In my if statement – I am showing specific elements based on selected option. I was wondering, If there is a way not to hard code dry-1 dry-2 dry-3 within my if statement and have an alternative way of doing it?

Also – I wouldn’t mind to hear some reviews on my current code 🙂 I have decided to start getting used to using controllers etc..

linux networking – Hide GKE cluster pods IP address behind single IP address in site to site VPN use case using GCP Cloud VPN

Currently I am developing nodejs application deployed to GKE cluster in google cloud platform. This application will need to call 3rd Party API which is only accessible through VPN so that I have to establish site to site VPN to the 3rd Party API provider network.

I know that site to site VPN can be implemented using GCP Cloud VPN and I have previous experience using GCP Cloud VPN. But the problem for me is this 3rd Party API will only allow one single IP address from my VPC accessing their network, which is a problem since all pods in the GKE cluster has their own ephemeral IP.

The question is that how I can make the outgoing API call from the GKE cluster to the 3rd party API comes only from one single IP address, so that the 3rd party provider admin can whitelist this single IP address to access their API?

I am thinking about using one linux VM as nat router, so that API call to the 3rd party API will go through this nat router first and then from nat router to the Cloud VPN gateway. But when I take a look at the VPC route table, I just can’t see how this method can be implemented, since in the VPC route table I can’t specify particular network segment as source. I can only set the destination and the next hop which will affect all the instances in the VPC.

Below is the link to view current topology of my VPC for reference :

Topology

Is this something can be done in GCP or maybe am I looking at the problem in the wrong way ?

Thank You

navigation – Some pages hide content unless “Read more” is clicked

What you’re probably looking at is a “View”. This view is probably showing a list of “Content” (nodes).

Now each node is probably being set to render in “Teaser” view mode. But since some of your node types (article for example) doesn’t have a “teaser” view mode configured, it shows the “Full” (or “Default”) view mode, which renders the “whole” thing.

What you need to do is find the View Mode that your content listing View is using, the Node Type of the content that’s showing up as Full, (for example ‘Basic Page’), then go to:

Structure > Content Types > (Content Type you want to configure) > Manage Display

And configure the view mode that your View is using to display the Read More link, show the body text as “Summary or Trimmed” etc.

sharepoint online – How to hide suite bar ribbon and header

Stack Exchange Network


Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

magento2 – hide free shipping method if my method is available

I have a method in two conditions.
1.checking whether the method is enable
2.checking for weight and quantity of products

public function collectRates(MagentoQuoteModelQuoteAddressRateRequest $request)
{
    if (!$this->getConfigFlag('active')) {
        return false;
    }

    / @var MagentoShippingModelRateResult $result */
    $result = $this->_rateResultFactory->create();

    / @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
    $method = $this->_rateMethodFactory->create();

    $method->setMethod($this->_code);
    $method->setMethodTitle($this->getConfigData('name'));

    $method->setCarrier($this->_code);
    $method->setCarrierTitle($this->getConfigData('title'));

    $amount = $this->getShippingPrice();

    $method->setPrice($amount);
    $method->setCost($amount);

    if ($request->getPackageWeight() < (float)$this->getConfigData('max_weight') && $request->getPackageQty() == 1) {
        return false;
    }

    $result->append($method);

    return $result;
}

menu bar – Why these window couldn’t appear in the right location after enabling “Auto hide menubar” feature on macOS Catalina?

On my mac, I have enabled auto hide menubar and auto hide Dock. After then, I found some applications didn’t work as expected.

Like Noizio, which is a white noise generation app, it often starts as mini windows append below the menubar like this.

Normal location

And I can use a shortcut to toggle this window when menubar is shown.
But when menubar is hidden.

The window toggled will appear at the left bottom with an ugly border. Just like this:

Anomarly location

This problem occurred with many applications, like “text scanner” (A text recognition app), “Calendar 366” (A calendar management app), I doubt the same reason causes it. Maybe when menubar is hidden, these Apps couldn’t know the location where it should draw. But some other apps like Fantastical works well as this situation.

Does anyone have more information about this problem? Can I do something to fix this problem?