Skip to content

Commit

Permalink
Merge pull request #15 from doxman13/tagteam_dialog
Browse files Browse the repository at this point in the history
Update version, fix somebug, improve UI, improve feature
  • Loading branch information
dongmx-vn authored Jan 6, 2023
2 parents 4ff4566 + 87c6b20 commit 49f64cf
Show file tree
Hide file tree
Showing 10 changed files with 4,313 additions and 2,681 deletions.
1 change: 0 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ chrome.storage.sync.get(
}
);

console.log("I'm here");
chrome.runtime.onMessage.addListener(function (textme, sender, sendResponse) {
console.log(textme.textyou);
//15 mins warning
Expand Down
26 changes: 15 additions & 11 deletions gtminjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ console.log('injector id currently is ' + result.myInjector + ' and it will '+ r

var s = document.createElement('script');
s.src = chrome.extension.getURL('script.js');
(document.head||document.documentElement).appendChild(s);
s.onload = function() {
var s2 = document.createElement('script');
s2.src = chrome.extension.getURL('script.js');
(document.head||document.documentElement).appendChild(s2);
s2.onload = function() {
var s3 = document.createElement('script');
s3.src = chrome.extension.getURL('script.js');
(document.head||document.documentElement).appendChild(s3);
};
};
try {
(document.head||document.documentElement).appendChild(s);
s.onload = function() {
var s2 = document.createElement('script');
s2.src = chrome.extension.getURL('script.js');
(document.head||document.documentElement).appendChild(s2);
s2.onload = function() {
var s3 = document.createElement('script');
s3.src = chrome.extension.getURL('script.js');
(document.head||document.documentElement).appendChild(s3);
};
};
} catch (error) {
console.error("gtminjector.js - has error", error);
}
17 changes: 14 additions & 3 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
[data-optionkl="Vietnam"] input[type="checkbox"] {
width: auto;
}
[data-optionkl="Vietnam"] ._yourGTM,

[data-optionkl="Vietnam"] .tabs-wrap {
display: none;
}
Expand Down Expand Up @@ -270,16 +270,27 @@ <h1> KL TAG TEAM </h1>
<div class="optionkl__option-row">
<label class="optionkl__option-col"><input type="text" id="optionkl__inputyourname" placeholder="Signal name, ex: Tim Cook"></label>
<label class="optionkl__option-col"><input type="text" id="optionkl__inputyourshortname" placeholder="Name, ex: Tim"></label>
<div class="optionkl__option-col">
<select id="optionkl__modecase">
<option value="Auto">Auto</option>
<option value="Development">Development</option>
<option value="ExtensionDefault">ExtensionDefault</option>
</select>
</div>
</div>
<div class="optionkl__option-row">
<div class="optionkl__option-col">
<label>
<input type="checkbox" id="optionkl__disable-dialog"> Disable dialog
<input type="checkbox" id="optionkl__disable-dialog"> Disable case overview
</label>
---
--
<label>
<input type="checkbox" id="optionkl__disable-focuscase"> Disable focus case
</label>
--
<label>
<input type="checkbox" id="optionkl__disable-stylebytheme"> Disable style
</label>
</div>
</div>
</div>
Expand Down
29 changes: 25 additions & 4 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ function save_options() {
console.log(country);
chrome.runtime.sendMessage({message: country});

var optionkl__modecase = document.getElementById('optionkl__modecase').value || "";
var optionkl__inputyourname = document.getElementById('optionkl__inputyourname').value || "";
var optionkl__inputyourshortname = document.getElementById('optionkl__inputyourshortname').value || "";
var optionkl__disable_dialog = document.getElementById('optionkl__disable-dialog').checked || false;
var optionkl__disable_focuscase = document.getElementById('optionkl__disable-focuscase').checked || false;
var optionkl__disable_stylebytheme = document.getElementById('optionkl__disable-stylebytheme').checked || false;

if(country == "Vietnam") {

Expand Down Expand Up @@ -50,10 +52,12 @@ function save_options() {
mycountry: country,
ouremail: youremail,

optionkl__modecase: optionkl__modecase,
optionkl__inputyourname: optionkl__inputyourname,
optionkl__inputyourshortname: optionkl__inputyourshortname,
optionkl__disable_dialog: optionkl__disable_dialog,
optionkl__disable_focuscase: optionkl__disable_focuscase
optionkl__disable_focuscase: optionkl__disable_focuscase,
optionkl__disable_stylebytheme: optionkl__disable_stylebytheme
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
Expand Down Expand Up @@ -115,10 +119,12 @@ function restore_options() {
ouremail: 'xxx@google.com',
myInjector: 'gtm-xxx',
gtmToDo: 'notStart',
optionkl__modecase: "",
optionkl__inputyourshortname: "",
optionkl__inputyourname: "",
optionkl__disable_dialog: false,
optionkl__disable_focuscase: false
optionkl__disable_focuscase: false,
optionkl__disable_stylebytheme: false
}, function(items) {
console.log(items);
console.log('why not here ' + items.myInjector + ' ' +items.gtmToDo);
Expand All @@ -127,9 +133,11 @@ function restore_options() {
document.getElementById('yourGTM').value = items.myInjector;

document.getElementById('optionkl').setAttribute("data-optionkl", items.mycountry);
document.getElementById('optionkl__modecase').value = items.optionkl__modecase;
document.getElementById('optionkl__inputyourshortname').value = items.optionkl__inputyourshortname;
document.getElementById('optionkl__inputyourname').value = items.optionkl__inputyourname;
document.getElementById('optionkl__disable-dialog').checked = items.optionkl__disable_dialog;
document.getElementById('optionkl__disable-stylebytheme').checked = items.optionkl__disable_stylebytheme;
document.getElementById('optionkl__disable-focuscase').checked = items.optionkl__disable_focuscase;


Expand All @@ -143,8 +151,21 @@ function restore_options() {
}

document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);
document.getElementById('save').addEventListener('click', save_options);

document.getElementById('country').addEventListener('change', function(e) {
var elem_parent = this.closest('[id="optionkl"]');
document.getElementById('optionkl').setAttribute("data-optionkl", this.value);


// Vietnamses
if(this.value === 'Vietnam') {
// elem_parent.querySelector('[name="youremail"]').value='';

}


});
$('#startGTM').click(inject_options);
$('#stopGTM').click(stop_injector);

Expand Down
97 changes: 53 additions & 44 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,57 +141,66 @@ s3.src = chrome.extension.getURL('script.js');


if (window.location.hostname === "cases.connect.corp.google.com" && window.location.href.indexOf("#/case/") > - 1) {
try {
function createDomWithText(domText, text, id) {
const dom = document.createElement("button");
dom.innerText = domText;
dom.id = id;

var _istopelm = document.querySelector(`.write-cards-wrapper:not([style*="display:none"]):not([style*="display: none"]) card.write-card.is-top`);
if(_istopelm) {
var _elmcasenote = _istopelm.querySelector(`.case-note`);
if(_elmcasenote) {
_elmcasenote.insertAdjacentElement("afterBegin", dom);

dom.addEventListener("click", () => {
if(typeof window.dataTagteam !== 'undefined') {
if(window.dataTagteam.hasOwnProperty("current_case")) {
if(window.dataTagteam.current_case.hasOwnProperty("tasks")) {
text = text.replace(`<span class="_tags_implement"></span>`, window.dataTagteam.current_case.tasks);
}
}
}

_elm_content = _istopelm.querySelector(`.editor [contenteditable="true"]`);
_elm_content.innerHTML += text;
_elm_content.dispatchEvent(new Event('input'));
_elm_content.dispatchEvent(new Event('focus'));
_elm_content.dispatchEvent(new Event('click'));
})
}
}
}


function createDomWithText(domText, text, id) {
const dom = document.createElement("button");
dom.innerText = domText
dom.id = id
document.querySelector(".case-note").prepend(dom);
// Select the node that will be observed for mutations
var targetNode = document.body;

dom.addEventListener("click", () => {
document.querySelector(".editor > div > div").innerHTML += text;
})
}
// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true, subtree: true };

// Callback function to execute when mutations are observed
var callback = function(mutationList, observer) {
var _istopelm = document.querySelector(`.write-cards-wrapper:not([style*="display:none"]):not([style*="display: none"]) card.write-card.is-top`);
if(_istopelm) {
if (_istopelm.querySelector("#pre-call") === null && _istopelm.querySelector("#on-call") === null) {
createDomWithText("Precall", `<ul dir="auto"><li>Emails or feedback from Advertiser/Seller (including seller request to join the call)[C]&nbsp;</li><li>Call being made in business hours[C]</li><li>Program ,task type (including special instructions),advertiser need and readiness [C]</li><li>Related cases [C]</li><li>CMS being used [C]</li><li>Gtag/GTM/GA already exists [C] (NA applicable only for Shopping or OCT cases)</li></ul>`, "pre-call");
createDomWithText("OnCall", `<b>Sub-status:</b>&nbsp; <p dir="auto"><b>Sub-status Reason:</b>&nbsp;</p><p dir="auto"><b>Speakeasy ID:&nbsp;</b></p><p dir="auto"><b>On Call Comments:</b>&nbsp;</p><p dir="auto"><b>Tags Implemented:</b>&nbsp;<span class="_tags_implement"></span></p><p dir="auto"><b>Screenshots:&nbsp;</b></p><p dir="auto"><b>Multiple CIDs:&nbsp;</b></p><p dir="auto"><b>On Call Screenshot:</b>&nbsp;</p>`, "on-call");
}
}
};

// Select the node that will be observed for mutations
var targetNode = document.body;

// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true, subtree: true };

// Callback function to execute when mutations are observed
var callback = function(mutationList, observer) {
for (var i = 0; i < mutationList.length; i++) {
if (mutationList[i].addedNodes.length > 0) {
for (var j = 0; j < mutationList[i].addedNodes.length; j++) {
if (mutationList[i].addedNodes[j]) {
if (mutationList[i].addedNodes[j].classList.length > 0) {
var classes = Array(mutationList[i].addedNodes[j].classList);
if (classes.indexOf("case-note")) {
if (document.querySelector("#pre-call") === null && document.querySelector("#on-call") === null) {
createDomWithText("Precall", `<ul dir="auto"><li>Emails or feedback from Advertiser/Seller (including seller request to join the call)[C]&nbsp;</li><li>Call being made in business hours[C]</li><li>Program ,task type (including special instructions),advertiser need and readiness [C]</li><li>Related cases [C]</li><li>CMS being used [C]</li><li>Gtag/GTM/GA already exists [C] (NA applicable only for Shopping or OCT cases)</li></ul>`, "pre-call");
createDomWithText("OnCall", `<b>Sub-status:</b>&nbsp;<p dir="auto"><b>Sub-status Reason:</b>&nbsp;</p><p dir="auto"><b>Speakeasy ID:&nbsp;</b></p><p dir="auto"><b>On Call Comments:</b>&nbsp;</p><p dir="auto"><b>Tags Implemented:</b>&nbsp;</p><p dir="auto"><b>Screenshots:&nbsp;</b></p><p dir="auto"><b>Multiple CIDs:&nbsp;</b></p><p dir="auto"><b>On Call Screenshot:</b>&nbsp;</p>`, "on-call");
}
}

}
}
}
}


}
};

// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);
// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);

// Later, you can stop observe
// Later, you can stop observe

} catch (error) {

}
}


Expand Down
Loading

0 comments on commit 49f64cf

Please sign in to comment.