Skip to content

Commit

Permalink
Fix for snuHyperlinkifyWorkNotes
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudkooi committed Mar 1, 2024
1 parent 3264094 commit fa9633e
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# CHANGELOG.md

## 7.3.4.0 (2024-02-22)
## 7.3.4.2 (2024-03-01)
Fixes / changes:
- Adjusted snuHyperlinkifyWorkNotes function to prevent issues when [code] tags are used in worknotes
- Preparations for Instance Button feature, that will be added in an upcoming release

## 7.3.4.0 (2024-02-25)
Features:
- Slash commands direct navigation can now be toggled via the shift key. Disabled state is indicated by low opacity of the numbers. Setting is stored per instance. This way unintended link navigation can be prevented. #philgoesdeep

Expand Down
26 changes: 26 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ function initializeContextMenus(){
}
});
}
// todo, will be used for sidepanel in upcoming release
// chrome.tabs.onUpdated.addListener(async (tabId, info, tab) => {
// console.log('onUpdated', tabId, info, tab);
// if (!tab.url) return;
// const url = new URL(tab.url);
// // Enables the side panel on google.com
// if (url.origin.includes('service-now.com')) {
// await chrome.sidePanel.setOptions({
// tabId,
// path: 'sidepanel.html',
// enabled: true
// });
// } else {
// // Disables the side panel on all other sites
// await chrome.sidePanel.setOptions({
// tabId,
// enabled: false
// });
// }
// });

chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {

Expand Down Expand Up @@ -124,6 +144,12 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
else if (message.event == "scriptsync") {
createScriptSyncTab(cookieStoreId);
}
// else if (message.event == "showsidepanel") {
// instance = (new URL(sender.tab.url)).host.replace(".service-now.com", "");
// setToChromeSyncStorage("instancebutton", message );
// chrome.sidePanel.open({ windowId: sender.tab.windowId, tabId: sender.tab.id });
// console.log('showsidepanel', message, sender);
// }
else if (message.event == "pop") {
pop();
}
Expand Down
3 changes: 2 additions & 1 deletion content_script_all_frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (isServiceNow) {
addScript('/js/purify.min.js', false); //needed for safe html insertion required by FF
addScript('inject.js', true);
//addScript('admin/snu-draggable-marker.js');
// if (window.self === window.top)
// addScript('admin/marker.js');
if (document.getElementById("filter") != null || location.pathname.startsWith("/now/")) {
addScript('inject_parent.js');
}
Expand Down
17 changes: 16 additions & 1 deletion inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4289,6 +4289,20 @@ function snuScriptSync() {
sncWait();
}

// function snuShowSidePanel() {
// var event = new CustomEvent(
// "snutils-event",
// {
// detail: {
// event: "showsidepanel",
// command: JSON.parse(localStorage.getItem("snuButtonPosition")) || {}
// }
// }
// );
// window.top.document.dispatchEvent(event);
// sncWait();
// }

function snuScriptSyncPostData(data) {
var event = new CustomEvent(
"snutils-event",
Expand Down Expand Up @@ -5182,7 +5196,8 @@ function snuHyperlinkifyWorkNotes() {
let newContent = crd.innerHTML.replace(urlRegex, function (url) {
return '<a href="' + url + '" target="_blank" title="[SN Utils] Converted to hyperlink">' + url + '</a>';
});
crd.innerHTML = DOMPurify.sanitize(newContent, { ADD_ATTR: ['target'] });
if (newContent) //dont apply when empty after regex, can happen when work note uses [code] tag
crd.innerHTML = DOMPurify.sanitize(newContent, { ADD_ATTR: ['target'] });
crd.classList.add('snuified');
})
}
Expand Down
68 changes: 68 additions & 0 deletions js/sidepanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
let instance;

document.addEventListener('DOMContentLoaded', function () {
const themeSwitch = document.getElementById('themeSwitch');
const body = document.body;

themeSwitch.addEventListener('change', function() {
body.classList.toggle('dark-mode');
});

const textInput = document.getElementById('textInput');
const fontSizeSlider = document.getElementById('fontSizeSlider');
const colorPicker = document.getElementById('colorPicker');

fontSizeSlider.addEventListener('input', function() {
textInput.style.fontSize = fontSizeSlider.value + 'px';
});

colorPicker.addEventListener('input', function() {
textInput.style.color = colorPicker.value;
});

/* Set for initial active tab when open the sidepanel */
(async () => {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
instance = (new URL(tab.url)).host.replace(".service-now.com", "");
document.querySelector('#instanceButton').innerHTML = JSON.stringify(await getFromSyncStorage("instancebutton"));
})();




});


function setToChromeSyncStorage(theName, theValue) {
var myobj = {};
myobj[instance + "-" + theName] = theValue;
chrome.storage.sync.set(myobj, function () {
});
}

//get an instance sync parameter
async function getFromSyncStorage(theName, callback) {
// Define the instance variable if it's not already defined
// Assuming 'instance' is a global variable or has been defined elsewhere
const instanceName = instance + "-" + theName;

// If a callback is provided, use the traditional callback approach
if (callback) {
chrome.storage.sync.get(instanceName, function (result) {
callback(result[instanceName]);
});
} else {
// If no callback is provided, return a promise
return new Promise((resolve, reject) => {
chrome.storage.sync.get(instanceName, function (result) {
if (chrome.runtime.lastError) {
// Reject the promise if there's an error
reject(chrome.runtime.lastError);
} else {
// Resolve the promise with the result
resolve(result[instanceName]);
}
});
});
}
}
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "SN Utils",
"description": "Productivity tools for ServiceNow. (Personal work, not affiliated to ServiceNow)",
"author": "Arnoud Kooi / arnoudkooi.com",
"version": "7.3.4.0",
"version": "7.3.4.2",
"manifest_version": 3,
"permissions": [
"activeTab",
Expand All @@ -12,7 +12,7 @@
"contextMenus",
"cookies"
],
"icons": {
"icons": {
"16": "images/icon16.png",
"24": "images/icon24.png",
"32": "images/icon32.png",
Expand Down
91 changes: 91 additions & 0 deletions sidepanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5 Page with Theme Toggle and Form</title>
<!-- Bootstrap CSS -->
<link href="/css/bootstrap.min.css" rel="stylesheet">
<style>
body.dark-mode {
background-color: #343a40;
color: #ffffff;
}

body.dark-mode .btn-secondary {
background-color: #6c757d;
border-color: #6c757d;
}

.form-control, .form-control-color, .form-range {
transition: background-color 0.5s ease, color 0.5s ease;
}

.dark-mode .form-control, .dark-mode .form-control-color, .dark-mode .form-range {
background-color: #495057;
color: #ffffff;
}
</style>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<div class="d-flex align-items-center">
<div class="text-end me-2">Light</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="themeSwitch">
<label class="form-check-label" for="themeSwitch">Dark</label>
</div>
</div>
</div>
</nav>

<div class="container py-5">
<div class="row">
<div class="col-md-8 mx-auto">
<!-- Form -->
<form id="customForm">
<div class="mb-3">
<label for="textInput" class="form-label">Text Input</label>
<input type="text" class="form-control" id="textInput" placeholder="Enter text">
</div>
<div class="mb-3">
<label for="fontSizeSlider" class="form-label">Font Size</label>
<input type="range" class="form-range" min="8" max="48" id="fontSizeSlider">
</div>
<div class="mb-3">
<label for="colorPicker" class="form-label">Pick a Color</label>
<input type="color" class="form-control form-control-color" id="colorPicker">
</div>
</form>
<pre id="instanceButton"></pre>
<input title="Background color" type="color" id="iconcolorbg" name="iconcolorbg" class="snu-instance-setting" value="#ff3333" list="colorslist" />
<input title="Text" type="text" id="icontext" name="icontext" maxlength="4" class="width30 snu-instance-setting" />
<input title="Text color" type="color" id="iconcolortext" name="iconcolortext" class="snu-instance-setting" value="#ffffff" list="colorslist" >

<datalist id="colorslist">
<option value="#ff3333">
<option value="#ffff33">
<option value="#86ED78">
<option value="#0066cc">
<option value="#ff8000">
<option value="#62D84E">
<option value="#009156">
<option value="#a0a0a0">
<option value="#ffffff">
<option value="#000000">
</datalist>
</div>
</div>
</div>

<!-- Bootstrap Bundle with Popper -->
<script src="/js/bootstrap.bundle.min.js"></script>
<script src="/js/sidepanel.js"></script>



</body>
</html>

0 comments on commit fa9633e

Please sign in to comment.