116 |
117 | [DL | RP]
118 | Blu-ray | MKV | h265 | ...
119 | |
120 |
121 | */
122 | let link = torrent_row.firstElementChild.children[1];
123 | //console.log(torrent_row);
124 | ///console.log(link);
125 |
126 | // (Experimental) compatibility with eva's torrent highlighter.
127 | // We check if the link contains spans.
128 | if (link.firstElementChild && link.firstElementChild.tagName === 'SPAN') {
129 | // In this case, our work is done and we just need to return
130 | // each span's text.
131 | isDebug() && console.log('span');
132 | let spans = link.children;
133 | for (let i = 0; i < spans.length; i++) {
134 | yield (spans[i].textContent);
135 | }
136 | } else {
137 | // Otherwise, we split and return the fields ourselves.
138 | isDebug() && console.log('textContent');
139 | let split_fields = link.textContent.replace('»', '').trim().split(' | ');
140 | for (let i = 0; i < split_fields.length; i++) {
141 | let field = split_fields[i];
142 | // This handles sub groups and region codes.
143 | // Will work incorrectly if a sub group contains |
144 | if (field.indexOf('(') !== -1 && field.charAt(field.length-1) === ')') {
145 | let s = field.split(' (');
146 | yield (s[0]);
147 | yield (s[1].trim(')'));
148 | } else if (field.charAt(field.length-2) === '.') {
149 | // If the second last char is a . we assume it's an
150 | // audio channel field.
151 | let s = field.split(' ');
152 | yield (s.slice(0, -1).join(' '));
153 | yield (s[s.length-1]);
154 | } else {
155 | yield (field);
156 | }
157 | }
158 | }
159 | }
160 |
161 | /**
162 | * Gets the sorting weight of the value `x` from the defined field mapping.
163 | * @param {string} x Field value
164 | */
165 | function get_weight(x) {
166 | return field_mapping[x];
167 | }
168 |
169 | /**
170 | * Iterates through each property of a and b from left to right,
171 | * comparing each property in turn using get_weight().
172 | *
173 | * For use as a comparison function in the .sort() method. Returns a positive
174 | * number when b < a, negative for a < b, and 0 if a = b.
175 | * @param {HTMLTableRowElement} a
176 | * @param {HTMLTableRowElement} b
177 | */
178 | function sort_comparer(a, b) {
179 | let a_iter = row_to_field_list(a);
180 | let b_iter = row_to_field_list(b);
181 |
182 | let a_object = {};
183 | while (!a_object.done) {
184 | a_object = a_iter.next();
185 | var b_object = b_iter.next();
186 | if (b_object.done) {
187 | // In case of one string being shorter than the other,
188 | // we sort the shorter one first.
189 | return 1;
190 | }
191 | let a_value = a_object.value;
192 | let b_value = b_object.value;
193 | if (a_value === b_value) {
194 | continue;
195 | }
196 | let a_weight = get_weight(a_value);
197 | let b_weight = get_weight(b_value);
198 | //_debug && (`a: ${a_value} ${a_weight}; b: ${b_value} ${b_weight}`)
199 | // Doing an arithmetic comparison only makes sense when both
200 | // a and b have defined weights.
201 | if (a_weight && b_weight) {
202 | // This integer subtraction results in the correct sorting.
203 | return a_weight - b_weight;
204 | } else {
205 | // Use string (alphabetical) sort on the original strings.
206 | return (a_value < b_value) ? -1 : 1;
207 | }
208 | }
209 | // If a and b have the same number of elements, they will finish at
210 | // the same time and are equal.
211 | if (b_object.done)
212 | return 0;
213 | // Otherwise, a < b.
214 | return -1;
215 | }
216 |
217 | /**
218 | * Sorts the torrent_rows, considering info rows.
219 | * Skips torrent groups when 3 or less torrents.
220 | *
221 | * @param {Array