Last active
June 24, 2024 08:29
-
-
Save hsayed21/45dfe751d552ea9ce44386439ae8a5dc to your computer and use it in GitHub Desktop.
Odoo Set Ticket to Open in a New Tab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Open Ticket in New Tab | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description try to take over the world! | |
// @author @hsayed21 | |
// @match https://www.posbank.me/web | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=posbank.me | |
// @updateURL https://gist.github.com/hsayed21/45dfe751d552ea9ce44386439ae8a5dc.js | |
// @downloadURL https://gist.github.com/hsayed21/45dfe751d552ea9ce44386439ae8a5dc.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
try | |
{ | |
function startAutoLink() { | |
const displayNamesWithoutLinks = document.querySelectorAll('tr.o_data_row td[name="display_name"]:not(:has(a))'); | |
if (displayNamesWithoutLinks.Length <= 0) | |
{ | |
return; | |
} | |
// Base URL part (you might want to customize this) | |
var loc = window.location; | |
var baseUrl = loc.origin + loc.pathname | |
// Convert NodeList to Array to use Array methods | |
const rows = Array.from(displayNamesWithoutLinks) | |
// Map 'td' elements to their parent 'tr' elements | |
.map(td => td.closest('tr.o_data_row')) | |
// Remove duplicates, as multiple 'td' without 'a' in the same row can lead to duplicate 'tr' references | |
.filter((value, index, self) => self.indexOf(value) === index); | |
// Iterate over each row | |
rows.forEach(function(row) { | |
// Add a click event listener that stops propagation | |
row.addEventListener('click', function(event) { | |
event.stopPropagation(); // Prevent any parent handler from being executed | |
//event.preventDefault(); // Prevent the default action of the click event | |
}, true); // Use capture to handle the event as it captures down to target | |
// Find a td with name='display_name' within the current row | |
var displayNameId = row.querySelector("td[name='display_name']"); | |
// Also, find a td with name='id' to get the ticket ID | |
var ticketId = row.querySelector("td[name='id']"); | |
// Proceed if both tds were found | |
if (displayNameId && ticketId) { | |
// Check if the td element does not have a child 'a' link | |
if (!displayNameId.querySelector('a')) { | |
// Get the text content of the display name and ticket ID tds | |
var displayName = displayNameId.textContent.trim(); | |
var strTicketId = ticketId.textContent.trim().replace(",", ""); // Assuming the ticket ID is the text content of the td | |
// Create a new 'a' element | |
var link = document.createElement('a'); | |
// Set the href attribute of the link to include the base URL and the ticket ID | |
// Ensure to adjust this URL formation as per your specific requirement | |
link.href = `${baseUrl}#id=${strTicketId}&${loc.hash.replace("#", "").replace("view_type=list", "view_type=form")}`; // Example: you might want a more specific path, or a different way to append the ID. | |
// Set the target attribute to '_blank' to open the link in a new tab | |
link.target = '_blank'; | |
// Set the text content of the link to the display name | |
link.textContent = displayName; | |
// Clear the content of the td element | |
displayNameId.innerHTML = ''; | |
// Append the link to the td element | |
displayNameId.appendChild(link); | |
} | |
} | |
}); | |
const ids = Array.from(document.querySelectorAll('tr.o_data_row td[name="id"]')).filter((elem) => elem.innerText.includes(",")); | |
ids.forEach(function(id) { | |
id.innerText = id.innerText.replace(",",""); | |
}); | |
} | |
setInterval(startAutoLink, 2000); | |
} | |
catch (error) | |
{ | |
console.error(error.message); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment