1
+
2
+ document . getElementById ( 'urlForm' ) . addEventListener ( 'submit' , async function ( event ) {
3
+ event . preventDefault ( ) ; // Previene il refresh della pagina
4
+ const url = document . getElementById ( 'url' ) . value ;
5
+ const resultsDiv = document . getElementById ( 'results' ) ;
6
+ resultsDiv . innerHTML = '' ; // Pulisce i risultati precedenti
7
+
8
+ try {
9
+ // Esegui la richiesta per ottenere il codice sorgente della pagina
10
+ const response = await fetch ( `https://api.allorigins.win/raw?url=${ encodeURIComponent ( url ) } ` ) ;
11
+ const text = await response . text ( ) ;
12
+
13
+ // RegExp per trovare "SKU" e i 40 caratteri successivi
14
+ const regex = / " s k u " .{ 0 , 40 } / g;
15
+ let match ;
16
+ const results = [ ] ;
17
+
18
+ // Esegui la ricerca nel testo HTML
19
+ while ( ( match = regex . exec ( text ) ) !== null ) {
20
+ results . push ( match [ 0 ] ) ;
21
+ }
22
+
23
+ // Visualizza i risultati
24
+ if ( results . length > 0 ) {
25
+ resultsDiv . innerHTML = "<h2>stringhe trovate:</h2>" ;
26
+ results . forEach ( result => {
27
+ const p = document . createElement ( 'p' ) ;
28
+ p . textContent = result ;
29
+ resultsDiv . appendChild ( p ) ;
30
+ } ) ;
31
+ } else {
32
+ resultsDiv . textContent = 'Nessuna stringa SKU trovata.' ;
33
+ }
34
+ } catch ( error ) {
35
+ resultsDiv . textContent = 'Errore durante il recupero del codice HTML: ' + error ;
36
+ }
37
+ } ) ;
38
+
39
+ function searchCOD ( ) {
40
+ const codice1 = document . getElementById ( 'codInput' ) . value . trim ( ) ;
41
+
42
+ if ( codice1 ) {
43
+ let nuovoURL = `https://www.olalla.it/wp-admin/post.php?post=${ codice1 } &action=edit` ;
44
+ window . open ( nuovoURL , '_blank' ) ; // Apri in una nuova scheda
45
+ } else {
46
+ alert ( "Per favore, inserisci un codice COD." ) ;
47
+ }
48
+ }
49
+
50
+ function searchSKU ( ) {
51
+ const codice2 = document . getElementById ( 'skuInput' ) . value . trim ( ) ;
52
+
53
+ if ( codice2 ) {
54
+ const nuovoURL = `https://www.olalla.it/wp-admin/edit.php?s=${ codice2 } &post_status=all&post_type=product&action=-1&seo_filter&product_type&stock_status&wcpv_product_vendors&paged=1&action2=-1` ;
55
+ window . open ( nuovoURL , '_blank' ) ; // Apri in una nuova scheda
56
+ } else {
57
+ alert ( "Per favore, inserisci un codice SKU." ) ;
58
+ }
59
+ }
60
+
61
+ function searchPROD ( ) {
62
+ const codice3 = document . getElementById ( 'prodInput' ) . value . trim ( ) ;
63
+
64
+ if ( codice3 ) {
65
+ let nuovoURL = `https://www.olalla.it/?s=${ codice3 } &post_type=product` ;
66
+ window . open ( nuovoURL , '_blank' ) ; // Apri in una nuova scheda
67
+ } else {
68
+ alert ( "Per favore, inserisci una descrizione migliore." ) ;
69
+ }
70
+ }
71
+
72
+ function resetForms ( ) {
73
+ document . getElementById ( 'codInput' ) . value = '' ;
74
+ document . getElementById ( 'url' ) . value = '' ;
75
+ document . getElementById ( 'prodInput' ) . value = '' ;
76
+ document . getElementById ( 'results' ) . innerHTML = '' ; // Pulisce i risultati
77
+ }
0 commit comments