Skip to content

Instantly share code, notes, and snippets.

@hsayed21
Last active June 24, 2024 08:29
Show Gist options
  • Select an option

  • Save hsayed21/45dfe751d552ea9ce44386439ae8a5dc to your computer and use it in GitHub Desktop.

Select an option

Save hsayed21/45dfe751d552ea9ce44386439ae8a5dc to your computer and use it in GitHub Desktop.

Revisions

  1. hsayed21 revised this gist Jun 24, 2024. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions OdooTicketOpenInNewTab.js
    Original file line number Diff line number Diff line change
    @@ -68,6 +68,11 @@
    }
    }
    });

    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);
  2. hsayed21 revised this gist Jun 22, 2024. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions OdooTicketOpenInNewTab.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,20 @@
    try
    // ==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))');
    @@ -59,4 +75,6 @@ try
    catch (error)
    {
    console.error(error.message);
    }
    }

    })();
  3. hsayed21 created this gist Mar 17, 2024.
    62 changes: 62 additions & 0 deletions OdooTicketOpenInNewTab.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    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);
    }
    }
    });
    }

    setInterval(startAutoLink, 2000);
    }
    catch (error)
    {
    console.error(error.message);
    }