|
1 | 1 | // ==UserScript==
|
2 | 2 | // @name UnityForumFixer
|
3 | 3 | // @namespace https://unitycoder.com/
|
4 |
| -// @version 0.81 (21.12.2024) |
| 4 | +// @version 0.82 (27.01.2025) |
5 | 5 | // @description Fixes For Unity Forums - https://github.com/unitycoder/UnityForumFixer
|
6 | 6 | // @author unitycoder.com
|
7 | 7 | // @match https://discussions.unity.com/latest
|
8 | 8 | // @match https://discussions.unity.com/t/*
|
| 9 | +// @require https://code.jquery.com/jquery-3.6.0.min.js |
9 | 10 | // ==/UserScript==
|
10 | 11 |
|
11 | 12 |
|
|
25 | 26 | TopicsViewCombineViewAndReplyCounts();
|
26 | 27 | OnMouseOverPostPreview();
|
27 | 28 | AddOnHoverOpenNotificationPanel();
|
| 29 | + FixPinButton(); |
| 30 | + |
28 | 31 |
|
29 | 32 | // update notification panel icons
|
30 | 33 | const currentUserButton = document.getElementById('toggle-current-user');
|
@@ -675,6 +678,72 @@ function AddOnHoverOpenNotificationPanel() {
|
675 | 678 | }
|
676 | 679 |
|
677 | 680 |
|
| 681 | +function FixPinButton() { |
| 682 | + // Select all buttons with the .topic-status class |
| 683 | + const buttons = document.querySelectorAll('.topic-statuses .topic-status'); |
| 684 | + |
| 685 | + // Get the CSRF token from the meta tags in the page head |
| 686 | + const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content; |
| 687 | + |
| 688 | + // Check if the CSRF token is available |
| 689 | + if (!csrfToken) { |
| 690 | + console.error('CSRF token not found'); |
| 691 | + return; |
| 692 | + } |
| 693 | + |
| 694 | + if (buttons.length > 0) { |
| 695 | + buttons.forEach((button) => { |
| 696 | + // Add a click event listener to each button |
| 697 | + button.addEventListener('click', function (event) { |
| 698 | + event.preventDefault(); // Prevent the default link behavior |
| 699 | + |
| 700 | + // Find the post ID by looking for the nearest <a> tag with a valid href |
| 701 | + const postLink = button.closest('td').querySelector('a.title'); |
| 702 | + const postId = postLink?.getAttribute('data-topic-id'); |
| 703 | + |
| 704 | + if (!postId) { |
| 705 | + console.error('Post ID not found for this button'); |
| 706 | + return; |
| 707 | + } |
| 708 | + |
| 709 | + console.log('Post ID:', postId); // Debug log to confirm the ID |
| 710 | + |
| 711 | + // Construct the PUT request URL using the extracted ID |
| 712 | + const url = `https://discussions.unity.com/t/${postId}/clear-pin`; |
| 713 | + |
| 714 | + // Send a PUT request with the CSRF token |
| 715 | + $.ajax({ |
| 716 | + url: url, |
| 717 | + type: 'PUT', |
| 718 | + headers: { |
| 719 | + 'X-CSRF-Token': csrfToken, // Include the CSRF token |
| 720 | + }, |
| 721 | + success: function (response) { |
| 722 | + console.log('PUT request successful:', response); |
| 723 | + |
| 724 | + // Hide the parent row of the clicked button |
| 725 | + const parentRow = button.closest('tr'); |
| 726 | + if (parentRow) { |
| 727 | + parentRow.style.display = 'none'; // Hides the row |
| 728 | + console.log(`Row with Post ID ${postId} hidden.`); |
| 729 | + } else { |
| 730 | + console.error('Parent row not found.'); |
| 731 | + } |
| 732 | + }, |
| 733 | + error: function (xhr, status, error) { |
| 734 | + console.error('XHR Status:', xhr.status); |
| 735 | + console.error('XHR Response Text:', xhr.responseText); |
| 736 | + console.error('Error:', error || 'Unknown error'); |
| 737 | + alert('Error sending request.'); |
| 738 | + }, |
| 739 | + }); |
| 740 | + }); |
| 741 | + }); |
| 742 | + } else { |
| 743 | + console.error('No notification buttons found.'); |
| 744 | + } |
| 745 | +} |
| 746 | + |
678 | 747 |
|
679 | 748 |
|
680 | 749 | // HELPER METHODS
|
|
0 commit comments