Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getCookie(name) {
- const matches = document.cookie
- .match(new RegExp(`(?:^|; )${name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1')}=([^;]*)`));
- return matches ? decodeURIComponent(matches[1]) : undefined;
- };
- var generateBindId = async (materialId, specId, profileId) => {
- var profileIdfromCookie = getCookie('profile_id');
- // var serviceAdress = `https://dnevnik-test.mos.ru/exam/player/api/binding?pid=${profileId || profileIdfromCookie}`;
- var serviceAdress = `https://uchebnik-stable.mos.ru/exam/player/api/binding?pid=${profileId || profileIdfromCookie}`;
- const data = {
- material_id: materialId,
- material_type: 'homework',
- test_material_id: specId,
- test_material_type: 'spec',
- };
- const options = {
- 'method': 'POST',
- 'credentials': 'include',
- 'headers': {
- 'accept': 'application/json;charset=UTF-8',
- 'content-type': 'application/json',
- },
- 'body': JSON.stringify(data),
- 'referrerPolicy': 'no-referrer-when-downgrade',
- 'mode': 'cors',
- };
- await fetch(
- serviceAdress,
- options
- ).then((res) => res.json())
- .then((res) => {
- console.log({ res });
- console.log('binding_id',res.binding_id);
- generateGroupId(res.binding_id);
- });
- console.log({ generateBindId });
- };
- generateBindId(63444709, 70193, 5787352)
- var generateGroupId = async (bindingId) => {
- const profileIdfromCookie = getCookie('profile_id');
- const serviceAdress = `https://uchebnik-stable.mos.ru/exam/rest/secure/testplayer/group?pid=${profileIdfromCookie}`;
- const data = {
- test_type: 'control_test',
- generation_context_type: 'homework',
- generation_by_id: bindingId,
- can_reanswer: true,
- can_see_result: true,
- can_switch: true,
- immediate_result: false,
- variants_count: 1
- };
- const options = {
- 'method': 'POST',
- 'credentials': 'include',
- 'headers': {
- 'accept': 'application/json;charset=UTF-8',
- 'content-type': 'application/json',
- },
- 'body': JSON.stringify(data),
- 'referrerPolicy': 'no-referrer-when-downgrade',
- 'mode': 'cors',
- };
- await fetch(serviceAdress, options)
- .then((res) => res.json())
- .then((res) => {
- console.log('group id', res.id);
- // const path = `https://uchebnik-stable.mos.ru/exam/test/homework/${bindingId}`;
- // console.log({ path });
- // window.open(path, '_blank');
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement