| 96 | } |
| 97 | |
| 98 | authentication() { |
| 99 | try { |
| 100 | utils.checkDoubleExecution(); |
| 101 | } catch (e) { |
| 102 | con.error(e); |
| 103 | } |
| 104 | try { |
| 105 | const code = utils.urlParam(this.url, 'code'); |
| 106 | if (!code) throw 'No code found!'; |
| 107 | this.call( |
| 108 | 'https://api.simkl.com/oauth/token', |
| 109 | JSON.stringify({ |
| 110 | code, |
| 111 | client_id: helper.client_id, |
| 112 | client_secret: __MAL_SYNC_KEYS__.simkl.secret, |
| 113 | redirect_uri: 'https://simkl.com/apps/chrome/mal-sync/connected/', |
| 114 | grant_type: 'authorization_code', |
| 115 | }), |
| 116 | false, |
| 117 | 'POST', |
| 118 | ) |
| 119 | .then(access_token => { |
| 120 | if ( |
| 121 | typeof access_token.error !== 'undefined' || |
| 122 | typeof access_token.access_token === 'undefined' |
| 123 | ) |
| 124 | throw access_token; |
| 125 | return api.settings.set('simklToken', access_token.access_token); |
| 126 | }) |
| 127 | .then(access_token => { |
| 128 | $('.firstStage').addClass('HideImportant'); |
| 129 | $('.secondStage').removeClass('HideImportant'); |
| 130 | $('.secondStage .SimklTVKodiheaddesc').css('text-align', 'center'); |
| 131 | }) |
| 132 | .catch(e => { |
| 133 | ee(e); |
| 134 | }); |
| 135 | } catch (e) { |
| 136 | ee(e); |
| 137 | } |
| 138 | |
| 139 | function ee(e) { |
| 140 | con.error(e); |
| 141 | $('.firstStage .SimklTVKodititletext, .secondStage .SimklTVKodititletext').text( |
| 142 | 'Something went wrong', |
| 143 | ); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | async streamingUI() { |
| 148 | con.log('Streaming UI'); |