Im trying to get this wordpress plugin (DRIFT Web chat) to disappear out of work hours so it shows in the hours of 09:00am (GMT) and 17:00PM (GMT) but I cannot seem to get it to work!
<script> var enableDisable = function(){var GMT_hours = new Date().getGMTHours() ;
if (GMT_hours > 08 && GMT_hours < 16){
document.getElementById('checktime').disabled = false;
}
else
{
document.getElementById('checktime').disabled = true;} }; setInterval(enableDisable, 1000*60); enableDisable(); var t = window.driftt = window.drift = window.driftt || [];if (!t.init) {
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
t.invoked = !0, t.methods = [ "identify", "config", "track", "reset" "debug", "show", "ping", "page", "hide", "off", "on" ],
t.factory = function(e) {
return function() {
var n = Array.prototype.slice.call(arguments);
return n.unshift(e), t.push(n), t;
};
}, t.methods.forEach(function(e) {
t[e] = t.factory(e);
}), t.load = function(t) {
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
var i = document.getElementsByTagName("script")[0];
i.parentNode.insertBefore(o, i);};} }(); drift.SNIPPET_VERSION = '0.3.1'; drift.load('n72gzwytbesr');
</script>
PLEASE HELP! Below are some screenshots if that helps...
This is the code given from DRIFT directly...
<!-- Start of Async Drift Code -->
<script> "use strict"; !function() { var t = window.driftt = window.drift = window.driftt || []; if (!t.init) {
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
t.invoked = !0, t.methods = [ "identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on" ],
t.factory = function(e) {
return function() {
var n = Array.prototype.slice.call(arguments);
return n.unshift(e), t.push(n), t;
};
}, t.methods.forEach(function(e) {
t[e] = t.factory(e);
}), t.load = function(t) {
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
var i = document.getElementsByTagName("script")[0];
i.parentNode.insertBefore(o, i); }; } }();drift.SNIPPET_VERSION = '0.3.1'; drift.load('n72gzwytbesr');
</script>
<!-- End of Async Drift Code -->
Whilst it is possible to do this using only javascript it would be easier to do with PHP.
In the plugins file includes/embed.php change this:
echo "<!-- Start Drift By WP-Plugin: Drift -->\n";
echo $drift_tag;
echo"<!-- end: Drift Code. -->\n";
to this:
if(date("Hi") < 1700 && date("Hi") > 900){
echo "<!-- Start Drift By WP-Plugin: Drift -->\n";
echo $drift_tag;
echo"<!-- end: Drift Code. -->\n";}
This will stop any additional JS from being embedded from Drift at all, instead of simply just not loading the embed but still loading the JS.