@@ -273,6 +273,119 @@ $(() => {
273
273
}
274
274
}
275
275
276
+ const startsUnFollowingPostProcess = ( responseData , key ) => {
277
+ console . log ( { responseData } ) ;
278
+
279
+
280
+ responseHandler ( key , { success : true , data : responseData . data , hasMore : responseData . hasMore } , ( ) => {
281
+ console . log ( responseData . hasMore ) ;
282
+ if ( responseData . hasMore )
283
+ window . location . href = responseData . hasMore ;
284
+ } ) ;
285
+ }
286
+
287
+
288
+ const startsUnFollowing = ( targets , key ) => {
289
+ const body = $ ( "body" ) ;
290
+ const followersList = [ ] ;
291
+ let hasNextPage = false ;
292
+ let finishedHere = true ;
293
+ if ( body . length > 0 ) {
294
+ const applicationMain = body . find ( "main#js-pjax-container" ) ;
295
+ if ( applicationMain . length > 0 ) {
296
+ const applicationContainer = applicationMain . find ( ".container-xl" ) ;
297
+ if ( applicationContainer . length > 0 && applicationContainer . children ( ) ) {
298
+ const followerContainers = applicationContainer . find ( ".d-table" ) ;
299
+ if ( followerContainers . length > 0 ) {
300
+ followerContainers . each ( function ( ) {
301
+ const followerItem = $ ( this ) ;
302
+ if ( followerItem . length > 0 ) {
303
+ if ( followerItem . hasClass ( "d-table" ) ) {
304
+ let follower = { } ;
305
+ try {
306
+ const userImage = followerItem . find ( "img" ) [ 0 ] ;
307
+ if ( userImage ) {
308
+ follower . image = $ ( userImage ) . attr ( "src" ) || undefined ;
309
+ }
310
+ } catch ( err ) { }
311
+ try {
312
+ const userName = followerItem . find ( "a[data-hovercard-type='user']>span" ) [ 0 ] ;
313
+
314
+ if ( userName ) {
315
+ follower . name = $ ( userName ) . text ( ) || undefined ;
316
+ }
317
+ } catch ( err ) { }
318
+ try {
319
+ const userUsername = followerItem . find ( "a[data-hovercard-type='user']>span" ) [ 1 ] ;
320
+
321
+ if ( userUsername ) {
322
+ follower . username = $ ( userUsername ) . text ( ) || undefined ;
323
+ }
324
+ } catch ( err ) { }
325
+ try {
326
+ const myStatus = followerItem . find ( "form:not([hidden='hidden']) input[type='submit']" ) [ 0 ] ;
327
+ if ( myStatus ) {
328
+ const statusValue = `${ $ ( myStatus ) . val ( ) } ` . toLowerCase ( ) . trim ( ) ;
329
+ follower . status = statusValue === "unfollow" ;
330
+ follower . action = follower . status ? myStatus : null ;
331
+ }
332
+ } catch ( err ) { }
333
+ if ( follower . username ) {
334
+ if ( Array . isArray ( targets ) && targets . length > 0 ) {
335
+ console . log ( { targets} ) ;
336
+ if ( targets . includes ( follower . username ) && follower . action ) {
337
+ console . log ( { follower} ) ;
338
+ finishedHere = false ;
339
+ if ( follower . action ) {
340
+ console . log ( $ ( follower . action ) ) ;
341
+ follower . action . click ( ) ;
342
+ }
343
+ }
344
+ }
345
+
346
+ followersList . push ( follower ) ;
347
+ }
348
+ }
349
+ }
350
+ } ) ;
351
+
352
+ }
353
+ }
354
+
355
+
356
+ const pageAction = applicationContainer . find ( ".paginate-container .pagination a" ) ;
357
+ console . warn ( pageAction ) ;
358
+ if ( pageAction ) {
359
+ const nextPage = pageAction [ pageAction . length - 1 ] ;
360
+ if ( nextPage ) {
361
+ const nextStepText = `${ $ ( nextPage ) . text ( ) } ` . toLowerCase ( ) . trim ( ) ;
362
+ if ( nextStepText === "next" ) {
363
+ hasNextPage = $ ( nextPage ) . attr ( "href" ) || undefined ;
364
+ }
365
+ }
366
+ }
367
+ }
368
+ }
369
+
370
+ if ( ! finishedHere ) {
371
+ setTimeout ( ( ) => {
372
+ console . log ( "reloading ...." ) ;
373
+ startsUnFollowing ( targets , key ) ;
374
+ } , 30 ) ;
375
+ } else {
376
+ startsUnFollowingPostProcess ( {
377
+ data : followersList ,
378
+ hasMore : hasNextPage
379
+ } , key ) ;
380
+ }
381
+
382
+ return ( {
383
+ data : followersList ,
384
+ hasMore : hasNextPage
385
+ } ) ;
386
+ }
387
+
388
+
276
389
const startsListing = ( key ) => {
277
390
let responseData = {
278
391
data : [ ] ,
@@ -301,7 +414,7 @@ $(() => {
301
414
} ;
302
415
let success = false ;
303
416
try {
304
- responseData = listFollowingFromCurrentTab ( ) ;
417
+ responseData = listFollowingFromCurrentTab ( ) ;
305
418
console . log ( { responseData } ) ;
306
419
success = true ;
307
420
} catch ( error ) {
@@ -315,6 +428,24 @@ $(() => {
315
428
} ) ;
316
429
}
317
430
431
+ const startsUnFollowFollowingUsers = ( key , targets ) => {
432
+ let responseData = {
433
+ data : [ ] ,
434
+ hasMore : false
435
+ } ;
436
+ let success = false ;
437
+ try {
438
+ responseData = startsUnFollowing ( targets , key ) ;
439
+ startsUnFollowingPostProcess ( responseData , key ) ;
440
+ console . log ( { responseData } ) ;
441
+ success = true ;
442
+ } catch ( error ) {
443
+
444
+ }
445
+
446
+ }
447
+
448
+
318
449
/**
319
450
* This function is sued to list followers
320
451
* @param {Object } payload
@@ -351,10 +482,10 @@ $(() => {
351
482
const unFollowFollowing = ( payload , response , key ) => {
352
483
const currentUrl = window . location . href ;
353
484
console . log ( { payload} ) ;
354
- if ( payload ) {
485
+ if ( payload && Array . isArray ( payload . targets ) ) {
355
486
if ( typeof response === "function" ) {
356
487
response ( true , currentUrl ) ;
357
- // startsListingFollowingUsers (key);
488
+ startsUnFollowFollowingUsers ( key , payload . targets ) ;
358
489
}
359
490
}
360
491
}
0 commit comments